linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] x86_64, i386: Add command line length to boot protocol
@ 2007-03-06 18:14 Bernhard Walle
  2007-03-06 18:21 ` Dave Jones
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Bernhard Walle @ 2007-03-06 18:14 UTC (permalink / raw)
  To: Andrew Morton, alon.barlev, ak; +Cc: linux-kernel

Because the command line is increased to 2048 characters after 2.6.21,
it's not possible for boot loaders and userspace tools to determine the length
of the command line the kernel can understand. The benefit of knowing the
length is that users can be warned if the command line size is too long which
prevents surprise if things don't work after bootup.

This patch updates the boot protocol to contain a field called
"cmdline_size" that contain the length of the command line (excluding
the terminating zero).

The patch also adds missing fields (of protocol version 2.05) to the x86_64
setup code.


Signed-off-by: Bernhard Walle <bwalle@suse.de>
Cc: Alon Bar-Lev <alon.barlev@gmail.com>
Cc: Andi Kleen <ak@suse.de>

---
 Documentation/i386/boot.txt |   23 +++++++++++++++++------
 arch/i386/boot/setup.S      |    7 ++++++-
 arch/x86_64/boot/setup.S    |   15 ++++++++++++++-
 3 files changed, 37 insertions(+), 8 deletions(-)

Index: longer-cmdline-boot-proto-mm/Documentation/i386/boot.txt
===================================================================
--- longer-cmdline-boot-proto-mm.orig/Documentation/i386/boot.txt
+++ longer-cmdline-boot-proto-mm/Documentation/i386/boot.txt
@@ -2,7 +2,7 @@
 		     ----------------------------
 
 		    H. Peter Anvin <hpa@zytor.com>
-			Last update 2007-01-26
+			Last update 2007-03-06
 
 On the i386 platform, the Linux kernel uses a rather complicated boot
 convention.  This has evolved partially due to historical aspects, as
@@ -35,9 +35,13 @@ Protocol 2.03:	(Kernel 2.4.18-pre1) Expl
 		initrd address available to the bootloader.
 
 Protocol 2.04:	(Kernel 2.6.14) Extend the syssize field to four bytes.
+
 Protocol 2.05:	(Kernel 2.6.20) Make protected mode kernel relocatable.
 		Introduce relocatable_kernel and kernel_alignment fields.
 
+Protocol 2.06:	(Kernel 2.6.22) Added a field that contains the size of
+		the boot command line
+
 
 **** MEMORY LAYOUT
 
@@ -133,6 +137,8 @@ Offset	Proto	Name		Meaning
 022C/4	2.03+	initrd_addr_max	Highest legal initrd address
 0230/4	2.05+	kernel_alignment Physical addr alignment required for kernel
 0234/1	2.05+	relocatable_kernel Whether kernel is relocatable or not
+0235/3	N/A	pad2		Unused
+0238/4	2.06+	cmdline_size	Maximum size of the kernel command line
 
 (1) For backwards compatibility, if the setup_sects field contains 0, the
     real value is 4.
@@ -233,6 +239,12 @@ filled out, however:
 	if your ramdisk is exactly 131072 bytes long and this field is
 	0x37FFFFFF, you can start your ramdisk at 0x37FE0000.)
 
+  cmdline_size:
+	The maximum size of the command line without the terminating
+	zero. This means that the command line can contain at most
+	cmdline_size characters. With protocol version 2.05 and
+	earlier, the maximum size was 255.
+
 
 **** THE KERNEL COMMAND LINE
 
@@ -241,11 +253,10 @@ loader to communicate with the kernel.  
 relevant to the boot loader itself, see "special command line options"
 below.
 
-The kernel command line is a null-terminated string currently up to
-255 characters long, plus the final null.  A string that is too long
-will be automatically truncated by the kernel, a boot loader may allow
-a longer command line to be passed to permit future kernels to extend
-this limit.
+The kernel command line is a null-terminated string. The maximum
+length can be retrieved from the field cmdline_size.  Before protocol
+version 2.06, the maximum was 255 characters.  A string that is too
+long will be automatically truncated by the kernel.
 
 If the boot protocol version is 2.02 or later, the address of the
 kernel command line is given by the header field cmd_line_ptr (see
Index: longer-cmdline-boot-proto-mm/arch/i386/boot/setup.S
===================================================================
--- longer-cmdline-boot-proto-mm.orig/arch/i386/boot/setup.S
+++ longer-cmdline-boot-proto-mm/arch/i386/boot/setup.S
@@ -52,6 +52,7 @@
 #include <asm/boot.h>
 #include <asm/e820.h>
 #include <asm/page.h>
+#include <asm/setup.h>
 	
 /* Signature words to ensure LILO loaded us right */
 #define SIG1	0xAA55
@@ -81,7 +82,7 @@ start:
 # This is the setup header, and it must start at %cs:2 (old 0x9020:2)
 
 		.ascii	"HdrS"		# header signature
-		.word	0x0205		# header version number (>= 0x0105)
+		.word	0x0206		# header version number (>= 0x0105)
 					# or else old loadlin-1.5 will fail)
 realmode_swtch:	.word	0, 0		# default_switch, SETUPSEG
 start_sys_seg:	.word	SYSSEG
@@ -171,6 +172,10 @@ relocatable_kernel:    .byte 0
 pad2:			.byte 0
 pad3:			.word 0
 
+cmdline_size:   .long   COMMAND_LINE_SIZE-1     #length of the command line,
+                                                #added with boot protocol
+                                                #version 2.06
+
 trampoline:	call	start_of_setup
 		.align 16
 					# The offset at this point is 0x240
Index: longer-cmdline-boot-proto-mm/arch/x86_64/boot/setup.S
===================================================================
--- longer-cmdline-boot-proto-mm.orig/arch/x86_64/boot/setup.S
+++ longer-cmdline-boot-proto-mm/arch/x86_64/boot/setup.S
@@ -51,6 +51,7 @@
 #include <asm/boot.h>
 #include <asm/e820.h>
 #include <asm/page.h>
+#include <asm/setup.h>
 
 /* Signature words to ensure LILO loaded us right */
 #define SIG1	0xAA55
@@ -80,7 +81,7 @@ start:
 # This is the setup header, and it must start at %cs:2 (old 0x9020:2)
 
 		.ascii	"HdrS"		# header signature
-		.word	0x0204		# header version number (>= 0x0105)
+		.word	0x0206		# header version number (>= 0x0105)
 					# or else old loadlin-1.5 will fail)
 realmode_swtch:	.word	0, 0		# default_switch, SETUPSEG
 start_sys_seg:	.word	SYSSEG
@@ -155,6 +156,18 @@ cmd_line_ptr:	.long 0			# (Header versio
 					# low memory 0x10000 or higher.
 
 ramdisk_max:	.long 0xffffffff
+
+kernel_alignment:  .long CONFIG_PHYSICAL_START 	#physical addr alignment
+						#(not relocatable =>
+						#fixed start == alignment)
+
+relocatable_kernel:     .byte 0                 #x86_64 is currently not
+pad2:			.byte 0                 #relocatable
+pad3:			.word 0
+
+cmdline_size:   .long   COMMAND_LINE_SIZE-1     #length of the command line,
+                                                #added with boot protocol
+                                                #version 2.06
 	
 trampoline:	call	start_of_setup
 		.align 16

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] x86_64, i386: Add command line length to boot protocol
  2007-03-06 18:14 [PATCH] x86_64, i386: Add command line length to boot protocol Bernhard Walle
@ 2007-03-06 18:21 ` Dave Jones
  2007-03-12 10:43   ` Pavel Machek
  2007-03-06 21:46 ` Alon Bar-Lev
  2007-03-07 10:05 ` Vivek Goyal
  2 siblings, 1 reply; 10+ messages in thread
From: Dave Jones @ 2007-03-06 18:21 UTC (permalink / raw)
  To: Andrew Morton, alon.barlev, ak, linux-kernel

On Tue, Mar 06, 2007 at 07:14:30PM +0100, Bernhard Walle wrote:

 > +cmdline_size:   .long   COMMAND_LINE_SIZE-1     #length of the command line,

Why a long? It's unlikely that someone is going to have a command line
bigger than 0xffff.

	Dave

-- 
http://www.codemonkey.org.uk

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] x86_64, i386: Add command line length to boot protocol
  2007-03-06 18:14 [PATCH] x86_64, i386: Add command line length to boot protocol Bernhard Walle
  2007-03-06 18:21 ` Dave Jones
@ 2007-03-06 21:46 ` Alon Bar-Lev
  2007-03-07 10:05 ` Vivek Goyal
  2 siblings, 0 replies; 10+ messages in thread
From: Alon Bar-Lev @ 2007-03-06 21:46 UTC (permalink / raw)
  To: alon.barlev, ak, linux-kernel

On 3/6/07, Bernhard Walle <bwalle@suse.de> wrote:
> +The kernel command line is a null-terminated string. The maximum
> +length can be retrieved from the field cmdline_size.  Before protocol
> +version 2.06, the maximum was 255 characters.  A string that is too
> +long will be automatically truncated by the kernel.

This is incorrect.
Since 2.02, the maximum was null terminated string truncated by kernel.

Best Regards,
Alon Bar-Lev.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] x86_64, i386: Add command line length to boot protocol
  2007-03-06 18:14 [PATCH] x86_64, i386: Add command line length to boot protocol Bernhard Walle
  2007-03-06 18:21 ` Dave Jones
  2007-03-06 21:46 ` Alon Bar-Lev
@ 2007-03-07 10:05 ` Vivek Goyal
  2 siblings, 0 replies; 10+ messages in thread
From: Vivek Goyal @ 2007-03-07 10:05 UTC (permalink / raw)
  To: Andrew Morton, alon.barlev, ak, linux-kernel

On Tue, Mar 06, 2007 at 07:14:30PM +0100, Bernhard Walle wrote:
> Because the command line is increased to 2048 characters after 2.6.21,
> it's not possible for boot loaders and userspace tools to determine the length
> of the command line the kernel can understand. The benefit of knowing the
> length is that users can be warned if the command line size is too long which
> prevents surprise if things don't work after bootup.

This makes sense to me. It can be used in kexec bootloader to warn user
if command line size exceeds than supported by kernel.

> 
> This patch updates the boot protocol to contain a field called
> "cmdline_size" that contain the length of the command line (excluding
> the terminating zero).
> 
> The patch also adds missing fields (of protocol version 2.05) to the x86_64
> setup code.

Today I have posted the x86_64 relocatable kernel patches which also fill
in missing 2.05 fields for x86_64.

[..]
>  #define SIG1	0xAA55
> @@ -81,7 +82,7 @@ start:
>  # This is the setup header, and it must start at %cs:2 (old 0x9020:2)
> 
>  		.ascii	"HdrS"		# header signature
> -		.word	0x0205		# header version number (>= 0x0105)
> +		.word	0x0206		# header version number (>= 0x0105)
>  					# or else old loadlin-1.5 will fail)
>  realmode_swtch:	.word	0, 0		# default_switch, SETUPSEG
>  start_sys_seg:	.word	SYSSEG
> @@ -171,6 +172,10 @@ relocatable_kernel:    .byte 0
>  pad2:			.byte 0
>  pad3:			.word 0
> 
> +cmdline_size:   .long   COMMAND_LINE_SIZE-1     #length of the command line,
> +                                                #added with boot protocol
> +                                                #version 2.06
> +

I think you will not require more than two bytes to represent supported
command line size so you can use replace pad3 and use these two bytes. These
were anyway padding bytes to be used for other requirements.

[..]
>  					# or else old loadlin-1.5 will fail)
>  realmode_swtch:	.word	0, 0		# default_switch, SETUPSEG
>  start_sys_seg:	.word	SYSSEG
> @@ -155,6 +156,18 @@ cmd_line_ptr:	.long 0			# (Header versio
>  					# low memory 0x10000 or higher.
> 
>  ramdisk_max:	.long 0xffffffff
> +
> +kernel_alignment:  .long CONFIG_PHYSICAL_START 	#physical addr alignment
> +						#(not relocatable =>
> +						#fixed start == alignment)
> +

This is wrong. CONFIG_PHYSICAL_START is not alignment. On x86_64 alignment
required is 2MB. (0x200000).

Thanks
Vivek

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] x86_64, i386: Add command line length to boot protocol
  2007-03-06 18:21 ` Dave Jones
@ 2007-03-12 10:43   ` Pavel Machek
  2007-03-12 20:55     ` Dave Jones
  0 siblings, 1 reply; 10+ messages in thread
From: Pavel Machek @ 2007-03-12 10:43 UTC (permalink / raw)
  To: Dave Jones, Andrew Morton, alon.barlev, ak, linux-kernel

On Tue 2007-03-06 13:21:34, Dave Jones wrote:
> On Tue, Mar 06, 2007 at 07:14:30PM +0100, Bernhard Walle wrote:
> 
>  > +cmdline_size:   .long   COMMAND_LINE_SIZE-1     #length of the command line,
> 
> Why a long? It's unlikely that someone is going to have a command line
> bigger than 0xffff.

Well, I could imagine overflowing that. Describing your numa setup,
excluding few bad bits of ram using memmap=exact, set up your boot
over iscsi on cmdline.... these are likely to eat insane ammount of
cmdline space.
							Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] x86_64, i386: Add command line length to boot protocol
  2007-03-12 10:43   ` Pavel Machek
@ 2007-03-12 20:55     ` Dave Jones
  2007-03-12 23:12       ` Pavel Machek
  0 siblings, 1 reply; 10+ messages in thread
From: Dave Jones @ 2007-03-12 20:55 UTC (permalink / raw)
  To: Pavel Machek; +Cc: Andrew Morton, alon.barlev, ak, linux-kernel

On Mon, Mar 12, 2007 at 10:43:52AM +0000, Pavel Machek wrote:
 > On Tue 2007-03-06 13:21:34, Dave Jones wrote:
 > > On Tue, Mar 06, 2007 at 07:14:30PM +0100, Bernhard Walle wrote:
 > > 
 > >  > +cmdline_size:   .long   COMMAND_LINE_SIZE-1     #length of the command line,
 > > 
 > > Why a long? It's unlikely that someone is going to have a command line
 > > bigger than 0xffff.
 > 
 > Well, I could imagine overflowing that. Describing your numa setup,
 > excluding few bad bits of ram using memmap=exact, set up your boot
 > over iscsi on cmdline.... these are likely to eat insane ammount of
 > cmdline space.

65535 characters? Are you for real?
Stop and think about just how big that is. If you have to create
a boot command line that long, you have serious, serious issues.

	Dave

-- 
http://www.codemonkey.org.uk

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] x86_64, i386: Add command line length to boot protocol
  2007-03-12 20:55     ` Dave Jones
@ 2007-03-12 23:12       ` Pavel Machek
  2007-03-12 23:39         ` Dave Jones
  0 siblings, 1 reply; 10+ messages in thread
From: Pavel Machek @ 2007-03-12 23:12 UTC (permalink / raw)
  To: Dave Jones, Andrew Morton, alon.barlev, ak, linux-kernel

Hi!

>  > >  > +cmdline_size:   .long   COMMAND_LINE_SIZE-1     #length of the command line,
>  > > 
>  > > Why a long? It's unlikely that someone is going to have a command line
>  > > bigger than 0xffff.
>  > 
>  > Well, I could imagine overflowing that. Describing your numa setup,
>  > excluding few bad bits of ram using memmap=exact, set up your boot
>  > over iscsi on cmdline.... these are likely to eat insane ammount of
>  > cmdline space.
> 
> 65535 characters? Are you for real?
> Stop and think about just how big that is. If you have to create
> a boot command line that long, you have serious, serious issues.

Well, it is about the same size as my .config...

I agree we are unlikely to hit it any time soon... I could imagine
some (ab)uses, like fixed_acpi_bios=<lots of hex digits>, but those
are ugly. I could also imagine some uses where entire embedded machine
is described at kernel commandline.

Yes, all those are ugly/unlikely. OTOH saving 2 bytes does not seem
like that great goal.
								Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] x86_64, i386: Add command line length to boot protocol
  2007-03-12 23:12       ` Pavel Machek
@ 2007-03-12 23:39         ` Dave Jones
  0 siblings, 0 replies; 10+ messages in thread
From: Dave Jones @ 2007-03-12 23:39 UTC (permalink / raw)
  To: Pavel Machek; +Cc: Andrew Morton, alon.barlev, ak, linux-kernel

On Tue, Mar 13, 2007 at 12:12:20AM +0100, Pavel Machek wrote:

 > > 65535 characters? Are you for real?
 > > Stop and think about just how big that is. If you have to create
 > > a boot command line that long, you have serious, serious issues.
 > 
 > Well, it is about the same size as my .config...

So? That has *nothing* to do with the boot command line

 > I agree we are unlikely to hit it any time soon... I could imagine
 > some (ab)uses, like fixed_acpi_bios=<lots of hex digits>, but those
 > are ugly.

That's beyond ugly, and rapidly heading towards 'loony'.

 > I could also imagine some uses where entire embedded machine
 > is described at kernel commandline.

There are far better ways to get configuration into the kernel
than the boot command line.

Anyways, I'm tired of arguing for the sake of arguing.
I really could care less.

	Dave

-- 
http://www.codemonkey.org.uk

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH] x86_64, i386: Add command line length to boot protocol
@ 2007-02-13 16:49 Bernhard Walle
  0 siblings, 0 replies; 10+ messages in thread
From: Bernhard Walle @ 2007-02-13 16:49 UTC (permalink / raw)
  To: H. Peter Anvin; +Cc: linux-kernel, Andi Kleen, Torsten Duwe

[Difference to previous attempt: cmdline_size is now without terminating
zero, requested by H. Peter Anvin.]

Because the command line is increased to 2048 characters after 2.6.20-rc6-mm1,
it's not possible for boot loaders and userspace tools to determine the length
of the command line the kernel can understand. The benefit of knowing the
length is that users can be warned if the command line size is too long which
prevents surprise if things don't work after bootup.

This patch updates the boot protocol to contain a field called
"cmdline_size" that contain the length of the command line (excluding
the terminating zero). It also updates documentation to set the length
to 255 characters before boot protocol 2.06, simply because there was no
kernel before that has another limit than 255 characters.

The patch also adds missing fields (of protocol version 2.05) to the x86_64
setup code.


Signed-off-by: Bernhard Walle <bwalle@suse.de>
Cc: Torsten Duwe <duwe@suse.de>
Cc: Andi Kleen <ak@suse.de>

---
 Documentation/i386/boot.txt |   23 +++++++++++++++++------
 arch/i386/boot/setup.S      |    7 ++++++-
 arch/x86_64/boot/setup.S    |   15 ++++++++++++++-
 3 files changed, 37 insertions(+), 8 deletions(-)

Index: b/Documentation/i386/boot.txt
===================================================================
--- a/Documentation/i386/boot.txt
+++ b/Documentation/i386/boot.txt
@@ -2,7 +2,7 @@
 		     ----------------------------
 
 		    H. Peter Anvin <hpa@zytor.com>
-			Last update 2007-01-26
+			Last update 2007-02-13
 
 On the i386 platform, the Linux kernel uses a rather complicated boot
 convention.  This has evolved partially due to historical aspects, as
@@ -35,9 +35,13 @@ Protocol 2.03:	(Kernel 2.4.18-pre1) Expl
 		initrd address available to the bootloader.
 
 Protocol 2.04:	(Kernel 2.6.14) Extend the syssize field to four bytes.
+
 Protocol 2.05:	(Kernel 2.6.20) Make protected mode kernel relocatable.
 		Introduce relocatable_kernel and kernel_alignment fields.
 
+Protocol 2.06:	(Kernel 2.6.21) Added a field that contains the size of
+		the boot command line
+
 
 **** MEMORY LAYOUT
 
@@ -133,6 +137,8 @@ Offset	Proto	Name		Meaning
 022C/4	2.03+	initrd_addr_max	Highest legal initrd address
 0230/4	2.05+	kernel_alignment Physical addr alignment required for kernel
 0234/1	2.05+	relocatable_kernel Whether kernel is relocatable or not
+0235/3	N/A	pad2		Unused
+0238/4	2.06+	cmdline_size	Maximum size of the kernel command line
 
 (1) For backwards compatibility, if the setup_sects field contains 0, the
     real value is 4.
@@ -233,6 +239,12 @@ filled out, however:
 	if your ramdisk is exactly 131072 bytes long and this field is
 	0x37FFFFFF, you can start your ramdisk at 0x37FE0000.)
 
+  cmdline_size:
+	The maximum size of the command line without the terminating
+	zero. This means that the command line can contain at most
+	cmdline_size characters. With protocol version 2.05 and
+	earlier, the maximum size was 255.
+
 
 **** THE KERNEL COMMAND LINE
 
@@ -241,11 +253,10 @@ loader to communicate with the kernel.  
 relevant to the boot loader itself, see "special command line options"
 below.
 
-The kernel command line is a null-terminated string currently up to
-255 characters long, plus the final null.  A string that is too long
-will be automatically truncated by the kernel, a boot loader may allow
-a longer command line to be passed to permit future kernels to extend
-this limit.
+The kernel command line is a null-terminated string. The maximum
+length can be retrieved from the field cmdline_size.  Before protocol
+version 2.06, the maximum was 255 characters.  A string that is too
+long will be automatically truncated by the kernel.
 
 If the boot protocol version is 2.02 or later, the address of the
 kernel command line is given by the header field cmd_line_ptr (see
Index: b/arch/i386/boot/setup.S
===================================================================
--- a/arch/i386/boot/setup.S
+++ b/arch/i386/boot/setup.S
@@ -52,6 +52,7 @@
 #include <asm/boot.h>
 #include <asm/e820.h>
 #include <asm/page.h>
+#include <asm/setup.h>
 	
 /* Signature words to ensure LILO loaded us right */
 #define SIG1	0xAA55
@@ -81,7 +82,7 @@ start:
 # This is the setup header, and it must start at %cs:2 (old 0x9020:2)
 
 		.ascii	"HdrS"		# header signature
-		.word	0x0205		# header version number (>= 0x0105)
+		.word	0x0206		# header version number (>= 0x0105)
 					# or else old loadlin-1.5 will fail)
 realmode_swtch:	.word	0, 0		# default_switch, SETUPSEG
 start_sys_seg:	.word	SYSSEG
@@ -171,6 +172,10 @@ relocatable_kernel:    .byte 0
 pad2:			.byte 0
 pad3:			.word 0
 
+cmdline_size:   .long   COMMAND_LINE_SIZE-1     #length of the command line,
+                                                #added with boot protocol
+                                                #version 2.06
+
 trampoline:	call	start_of_setup
 		.align 16
 					# The offset at this point is 0x240
Index: b/arch/x86_64/boot/setup.S
===================================================================
--- a/arch/x86_64/boot/setup.S
+++ b/arch/x86_64/boot/setup.S
@@ -51,6 +51,7 @@
 #include <asm/boot.h>
 #include <asm/e820.h>
 #include <asm/page.h>
+#include <asm/setup.h>
 
 /* Signature words to ensure LILO loaded us right */
 #define SIG1	0xAA55
@@ -80,7 +81,7 @@ start:
 # This is the setup header, and it must start at %cs:2 (old 0x9020:2)
 
 		.ascii	"HdrS"		# header signature
-		.word	0x0204		# header version number (>= 0x0105)
+		.word	0x0206		# header version number (>= 0x0105)
 					# or else old loadlin-1.5 will fail)
 realmode_swtch:	.word	0, 0		# default_switch, SETUPSEG
 start_sys_seg:	.word	SYSSEG
@@ -155,6 +156,18 @@ cmd_line_ptr:	.long 0			# (Header versio
 					# low memory 0x10000 or higher.
 
 ramdisk_max:	.long 0xffffffff
+
+kernel_alignment:  .long CONFIG_PHYSICAL_START 	#physical addr alignment
+						#(not relocatable =>
+						#fixed start == alignment)
+
+relocatable_kernel:     .byte 0                 #x86_64 is currently not
+pad2:			.byte 0                 #relocatable
+pad3:			.word 0
+
+cmdline_size:   .long   COMMAND_LINE_SIZE-1     #length of the command line,
+                                                #added with boot protocol
+                                                #version 2.06
 	
 trampoline:	call	start_of_setup
 		.align 16

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH] x86_64, i386: Add command line length to boot protocol
@ 2007-02-04 18:05 Bernhard Walle
  0 siblings, 0 replies; 10+ messages in thread
From: Bernhard Walle @ 2007-02-04 18:05 UTC (permalink / raw)
  To: H. Peter Anvin; +Cc: Andreas Kleen, Torsten Duwe, linux-kernel

Because the command line is increased to 2048 characters after 2.6.20-rc6-mm1,
it's not possible for boot loaders and userspace tools to determine the length
of the command line the kernel can understand. The benefit of knowing that
length is that users can be warned if the command line size is too long which
prevents surprise if things don't work after bootup.

This patch updates the boot protocol to contain a field called "cmdline_size"
that contain the length of the command line. It also updates documentation to
set the length to 256 characters before boot protocol 2.06, simply because
there was no kernel before that has another limit than 256 characters.

The patch also adds missing fields (of protocol version 2.05) to the x86_64
setup code.


Signed-off-by: Bernhard Walle <bwalle@suse.de>

---
 Documentation/i386/boot.txt |   23 +++++++++++++++++------
 arch/i386/boot/setup.S      |    7 ++++++-
 arch/x86_64/boot/setup.S    |   15 ++++++++++++++-
 3 files changed, 37 insertions(+), 8 deletions(-)

Index: linux-2.6.20-rc6-mm3/Documentation/i386/boot.txt
===================================================================
--- linux-2.6.20-rc6-mm3.orig/Documentation/i386/boot.txt
+++ linux-2.6.20-rc6-mm3/Documentation/i386/boot.txt
@@ -2,7 +2,7 @@
 		     ----------------------------
 
 		    H. Peter Anvin <hpa@zytor.com>
-			Last update 2007-01-26
+			Last update 2007-02-03
 
 On the i386 platform, the Linux kernel uses a rather complicated boot
 convention.  This has evolved partially due to historical aspects, as
@@ -35,9 +35,13 @@ Protocol 2.03:	(Kernel 2.4.18-pre1) Expl
 		initrd address available to the bootloader.
 
 Protocol 2.04:	(Kernel 2.6.14) Extend the syssize field to four bytes.
+
 Protocol 2.05:	(Kernel 2.6.20) Make protected mode kernel relocatable.
 		Introduce relocatable_kernel and kernel_alignment fields.
 
+Protocol 2.06:	(Kernel 2.6.21) Added a field that contains the size of
+		the boot command line
+
 
 **** MEMORY LAYOUT
 
@@ -133,6 +137,8 @@ Offset	Proto	Name		Meaning
 022C/4	2.03+	initrd_addr_max	Highest legal initrd address
 0230/4	2.05+	kernel_alignment Physical addr alignment required for kernel
 0234/1	2.05+	relocatable_kernel Whether kernel is relocatable or not
+0235/3	N/A	pad2		Unused
+0238/4	2.06+	cmdline_size	Maximum size of the kernel command line
 
 (1) For backwards compatibility, if the setup_sects field contains 0, the
     real value is 4.
@@ -233,6 +239,12 @@ filled out, however:
 	if your ramdisk is exactly 131072 bytes long and this field is
 	0x37FFFFFF, you can start your ramdisk at 0x37FE0000.)
 
+  cmdline_size:
+	The maximum size of the command line including the terminating
+	zero. This means that the command line can contain at most
+	(cmdline_size - 1) characters.  With protocol version 2.05 and
+	earlier, the maximum size was 256.
+
 
 **** THE KERNEL COMMAND LINE
 
@@ -241,11 +253,10 @@ loader to communicate with the kernel.  
 relevant to the boot loader itself, see "special command line options"
 below.
 
-The kernel command line is a null-terminated string currently up to
-255 characters long, plus the final null.  A string that is too long
-will be automatically truncated by the kernel, a boot loader may allow
-a longer command line to be passed to permit future kernels to extend
-this limit.
+The kernel command line is a null-terminated string. The maximum
+length can be retrieved from the field cmdline_size.  Before protocol
+version 2.06, the maximum was 255 characters.  A string that is too
+long will be automatically truncated by the kernel.
 
 If the boot protocol version is 2.02 or later, the address of the
 kernel command line is given by the header field cmd_line_ptr (see
Index: linux-2.6.20-rc6-mm3/arch/i386/boot/setup.S
===================================================================
--- linux-2.6.20-rc6-mm3.orig/arch/i386/boot/setup.S
+++ linux-2.6.20-rc6-mm3/arch/i386/boot/setup.S
@@ -52,6 +52,7 @@
 #include <asm/boot.h>
 #include <asm/e820.h>
 #include <asm/page.h>
+#include <asm/setup.h>
 	
 /* Signature words to ensure LILO loaded us right */
 #define SIG1	0xAA55
@@ -81,7 +82,7 @@ start:
 # This is the setup header, and it must start at %cs:2 (old 0x9020:2)
 
 		.ascii	"HdrS"		# header signature
-		.word	0x0205		# header version number (>= 0x0105)
+		.word	0x0206		# header version number (>= 0x0105)
 					# or else old loadlin-1.5 will fail)
 realmode_swtch:	.word	0, 0		# default_switch, SETUPSEG
 start_sys_seg:	.word	SYSSEG
@@ -171,6 +172,10 @@ relocatable_kernel:    .byte 0
 pad2:			.byte 0
 pad3:			.word 0
 
+cmdline_size:   .long   COMMAND_LINE_SIZE       #length of the command line,
+                                                #added with boot protocol
+                                                #version 2.06
+
 trampoline:	call	start_of_setup
 		.align 16
 					# The offset at this point is 0x240
Index: linux-2.6.20-rc6-mm3/arch/x86_64/boot/setup.S
===================================================================
--- linux-2.6.20-rc6-mm3.orig/arch/x86_64/boot/setup.S
+++ linux-2.6.20-rc6-mm3/arch/x86_64/boot/setup.S
@@ -51,6 +51,7 @@
 #include <asm/boot.h>
 #include <asm/e820.h>
 #include <asm/page.h>
+#include <asm/setup.h>
 
 /* Signature words to ensure LILO loaded us right */
 #define SIG1	0xAA55
@@ -80,7 +81,7 @@ start:
 # This is the setup header, and it must start at %cs:2 (old 0x9020:2)
 
 		.ascii	"HdrS"		# header signature
-		.word	0x0204		# header version number (>= 0x0105)
+		.word	0x0206		# header version number (>= 0x0105)
 					# or else old loadlin-1.5 will fail)
 realmode_swtch:	.word	0, 0		# default_switch, SETUPSEG
 start_sys_seg:	.word	SYSSEG
@@ -155,6 +156,18 @@ cmd_line_ptr:	.long 0			# (Header versio
 					# low memory 0x10000 or higher.
 
 ramdisk_max:	.long 0xffffffff
+
+kernel_alignment:  .long CONFIG_PHYSICAL_START 	#physical addr alignment
+						#(not relocatable =>
+						#fixed start == alignment)
+
+relocatable_kernel:     .byte 0                 #x86_64 is currently not
+pad2:			.byte 0                 #relocatable
+pad3:			.word 0
+
+cmdline_size:   .long   COMMAND_LINE_SIZE       #length of the command line,
+                                                #added with boot protocol
+                                                #version 2.06
 	
 trampoline:	call	start_of_setup
 		.align 16


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2007-03-12 23:40 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-03-06 18:14 [PATCH] x86_64, i386: Add command line length to boot protocol Bernhard Walle
2007-03-06 18:21 ` Dave Jones
2007-03-12 10:43   ` Pavel Machek
2007-03-12 20:55     ` Dave Jones
2007-03-12 23:12       ` Pavel Machek
2007-03-12 23:39         ` Dave Jones
2007-03-06 21:46 ` Alon Bar-Lev
2007-03-07 10:05 ` Vivek Goyal
  -- strict thread matches above, loose matches on Subject: below --
2007-02-13 16:49 Bernhard Walle
2007-02-04 18:05 Bernhard Walle

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).