diff options
author | Alon Bar-Lev <alon.barlev@gmail.com> | 2007-02-12 03:53:52 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-02-12 12:48:37 -0500 |
commit | 30d7e0d466b3ac0b5ef77e4062bf9385f0d72270 (patch) | |
tree | cff57621e9e5b8898abb2982ec3b0b7d0e6eac88 | |
parent | ff91691bccdb741efb2df0489058a4961fa79598 (diff) |
[PATCH] Dynamic kernel command-line: common
Current implementation stores a static command-line buffer allocated to
COMMAND_LINE_SIZE size. Most architectures stores two copies of this buffer,
one for future reference and one for parameter parsing.
Current kernel command-line size for most architecture is much too small for
module parameters, video settings, initramfs paramters and much more. The
problem is that setting COMMAND_LINE_SIZE to a grater value, allocates static
buffers.
In order to allow a greater command-line size, these buffers should be
dynamically allocated or marked as init disposable buffers, so unused memory
can be released.
This patch renames the static saved_command_line variable into
boot_command_line adding __initdata attribute, so that it can be disposed
after initialization. This rename is required so applications that use
saved_command_line will not be affected by this change.
It reintroduces saved_command_line as dynamically allocated buffer to match
the data in boot_command_line.
It also mark secondary command-line buffer as __initdata, and copies it to
dynamically allocated static_command_line buffer components may hold reference
to it after initialization.
This patch is for linux-2.6.20-rc4-mm1 and is divided to target each
architecture. I could not check this in any architecture so please forgive me
if I got it wrong.
The per-architecture modification is very simple, use boot_command_line in
place of saved_command_line. The common code is the change into dynamic
command-line.
This patch:
1. Rename saved_command_line into boot_command_line, mark as init
disposable.
2. Add dynamic allocated saved_command_line.
3. Add dynamic allocated static_command_line.
4. During startup copy: boot_command_line into saved_command_line. arch
command_line into static_command_line.
5. Parse static_command_line and not arch command_line, so arch
command_line may be freed.
Signed-off-by: Alon Bar-Lev <alon.barlev@gmail.com>
Cc: Andi Kleen <ak@muc.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Richard Henderson <rth@twiddle.net>
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Cc: Russell King <rmk@arm.linux.org.uk>
Cc: Ian Molton <spyro@f2s.com>
Cc: Mikael Starvik <starvik@axis.com>
Cc: David Howells <dhowells@redhat.com>
Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: Kyle McMartin <kyle@mcmartin.ca>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Hirokazu Takata <takata@linux-m32r.org>
Cc: Paul Mundt <lethal@linux-sh.org>
Cc: Kazumoto Kojima <kkojima@rr.iij4u.or.jp>
Cc: Richard Curnow <rc@rc0.org.uk>
Cc: William Lee Irwin III <wli@holomorphy.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Jeff Dike <jdike@addtoit.com>
Cc: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
Cc: Miles Bader <uclinux-v850@lsi.nec.co.jp>
Cc: Chris Zankel <chris@zankel.net>
Cc: "Luck, Tony" <tony.luck@intel.com>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Roman Zippel <zippel@linux-m68k.org>
Cc: Greg Ungerer <gerg@uclinux.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | include/linux/init.h | 5 | ||||
-rw-r--r-- | init/main.c | 29 |
2 files changed, 27 insertions, 7 deletions
diff --git a/include/linux/init.h b/include/linux/init.h index c65f5107d512..e290a010e3f2 100644 --- a/include/linux/init.h +++ b/include/linux/init.h | |||
@@ -67,7 +67,8 @@ extern initcall_t __con_initcall_start[], __con_initcall_end[]; | |||
67 | extern initcall_t __security_initcall_start[], __security_initcall_end[]; | 67 | extern initcall_t __security_initcall_start[], __security_initcall_end[]; |
68 | 68 | ||
69 | /* Defined in init/main.c */ | 69 | /* Defined in init/main.c */ |
70 | extern char saved_command_line[]; | 70 | extern char __initdata boot_command_line[]; |
71 | extern char *saved_command_line; | ||
71 | extern unsigned int reset_devices; | 72 | extern unsigned int reset_devices; |
72 | 73 | ||
73 | /* used by init/main.c */ | 74 | /* used by init/main.c */ |
@@ -164,7 +165,7 @@ struct obs_kernel_param { | |||
164 | #define early_param(str, fn) \ | 165 | #define early_param(str, fn) \ |
165 | __setup_param(str, fn, fn, 1) | 166 | __setup_param(str, fn, fn, 1) |
166 | 167 | ||
167 | /* Relies on saved_command_line being set */ | 168 | /* Relies on boot_command_line being set */ |
168 | void __init parse_early_param(void); | 169 | void __init parse_early_param(void); |
169 | #endif /* __ASSEMBLY__ */ | 170 | #endif /* __ASSEMBLY__ */ |
170 | 171 | ||
diff --git a/init/main.c b/init/main.c index 4e88bddfbebf..4e9e92bb2b89 100644 --- a/init/main.c +++ b/init/main.c | |||
@@ -121,8 +121,12 @@ extern void time_init(void); | |||
121 | void (*late_time_init)(void); | 121 | void (*late_time_init)(void); |
122 | extern void softirq_init(void); | 122 | extern void softirq_init(void); |
123 | 123 | ||
124 | /* Untouched command line (eg. for /proc) saved by arch-specific code. */ | 124 | /* Untouched command line saved by arch-specific code. */ |
125 | char saved_command_line[COMMAND_LINE_SIZE]; | 125 | char __initdata boot_command_line[COMMAND_LINE_SIZE]; |
126 | /* Untouched saved command line (eg. for /proc) */ | ||
127 | char *saved_command_line; | ||
128 | /* Command line for parameter parsing */ | ||
129 | static char *static_command_line; | ||
126 | 130 | ||
127 | static char *execute_command; | 131 | static char *execute_command; |
128 | static char *ramdisk_execute_command; | 132 | static char *ramdisk_execute_command; |
@@ -400,6 +404,20 @@ static void __init smp_init(void) | |||
400 | #endif | 404 | #endif |
401 | 405 | ||
402 | /* | 406 | /* |
407 | * We need to store the untouched command line for future reference. | ||
408 | * We also need to store the touched command line since the parameter | ||
409 | * parsing is performed in place, and we should allow a component to | ||
410 | * store reference of name/value for future reference. | ||
411 | */ | ||
412 | static void __init setup_command_line(char *command_line) | ||
413 | { | ||
414 | saved_command_line = alloc_bootmem(strlen (boot_command_line)+1); | ||
415 | static_command_line = alloc_bootmem(strlen (command_line)+1); | ||
416 | strcpy (saved_command_line, boot_command_line); | ||
417 | strcpy (static_command_line, command_line); | ||
418 | } | ||
419 | |||
420 | /* | ||
403 | * We need to finalize in a non-__init function or else race conditions | 421 | * We need to finalize in a non-__init function or else race conditions |
404 | * between the root thread and the init thread may cause start_kernel to | 422 | * between the root thread and the init thread may cause start_kernel to |
405 | * be reaped by free_initmem before the root thread has proceeded to | 423 | * be reaped by free_initmem before the root thread has proceeded to |
@@ -453,7 +471,7 @@ void __init parse_early_param(void) | |||
453 | return; | 471 | return; |
454 | 472 | ||
455 | /* All fall through to do_early_param. */ | 473 | /* All fall through to do_early_param. */ |
456 | strlcpy(tmp_cmdline, saved_command_line, COMMAND_LINE_SIZE); | 474 | strlcpy(tmp_cmdline, boot_command_line, COMMAND_LINE_SIZE); |
457 | parse_args("early options", tmp_cmdline, NULL, 0, do_early_param); | 475 | parse_args("early options", tmp_cmdline, NULL, 0, do_early_param); |
458 | done = 1; | 476 | done = 1; |
459 | } | 477 | } |
@@ -503,6 +521,7 @@ asmlinkage void __init start_kernel(void) | |||
503 | printk(KERN_NOTICE); | 521 | printk(KERN_NOTICE); |
504 | printk(linux_banner); | 522 | printk(linux_banner); |
505 | setup_arch(&command_line); | 523 | setup_arch(&command_line); |
524 | setup_command_line(command_line); | ||
506 | unwind_setup(); | 525 | unwind_setup(); |
507 | setup_per_cpu_areas(); | 526 | setup_per_cpu_areas(); |
508 | smp_prepare_boot_cpu(); /* arch-specific boot-cpu hooks */ | 527 | smp_prepare_boot_cpu(); /* arch-specific boot-cpu hooks */ |
@@ -520,9 +539,9 @@ asmlinkage void __init start_kernel(void) | |||
520 | preempt_disable(); | 539 | preempt_disable(); |
521 | build_all_zonelists(); | 540 | build_all_zonelists(); |
522 | page_alloc_init(); | 541 | page_alloc_init(); |
523 | printk(KERN_NOTICE "Kernel command line: %s\n", saved_command_line); | 542 | printk(KERN_NOTICE "Kernel command line: %s\n", boot_command_line); |
524 | parse_early_param(); | 543 | parse_early_param(); |
525 | parse_args("Booting kernel", command_line, __start___param, | 544 | parse_args("Booting kernel", static_command_line, __start___param, |
526 | __stop___param - __start___param, | 545 | __stop___param - __start___param, |
527 | &unknown_bootoption); | 546 | &unknown_bootoption); |
528 | if (!irqs_disabled()) { | 547 | if (!irqs_disabled()) { |