init: keep boot_command_line after init
PATCH 1/1 init: keep boot_command_line after init
From: Arnd Bergmann <[email protected]>
The boot command line is not available after the init section gets discarded, so adding a permanent reference to it causes a link time warning:
WARNING: modpost: vmlinux: section mismatch in reference: cmdline_load_proc_show+0x2 (section: .text) -> boot_command_line (section: .init.data)
ERROR: modpost: Section mismatches detected.
Set CONFIG_SECTION_MISMATCH_WARN_ONLY=y to allow them.
Change it to __ro_after_init to prevent it from getting freed.
--- include/linux/init.h | 2 +- init/main.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
include/linux/init.h +1 -1
@@ -143,7 +143,7 @@ struct file_system_type;/* Defined in init/main.c */ extern int do_one_initcall (initcall_t fn); -extern char __initdata boot_command_line[]; +extern char boot_command_line[];extern char *saved_command_line;extern unsigned int saved_command_line_len;extern unsigned int reset_devices;
init/main.c +1 -1
@@ -135,7 +135,7 @@ EXPORT_SYMBOL(system_state);void (*__initdata late_time_init)(void );/* Untouched command line saved by arch-specific code. */ -char __initdata boot_command_line[COMMAND_LINE_SIZE ]; +char boot_command_line[COMMAND_LINE_SIZE ]__ro_after_init ;/* Untouched saved command line (eg. for /proc) */ char *saved_command_line__ro_after_init ;unsigned int saved_command_line_len__ro_after_init ;
Signature · 1 line
2.39.2
Quoted 7 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
The boot command line is not available after the init section gets discarded, so adding a permanent reference to it causes a link time warning:
WARNING: modpost: vmlinux: section mismatch in reference:
cmdline_load_proc_show+0x2(section: .text) ->boot_command_line(section: .init.data)
cmdline_load_proc_show is probably inlined, but should it also be marked __init? It's lone call site seems to be __init AFAICT.
Thanks for the patch!
Quoted 41 lines
ERROR: modpost: Section mismatches detected. Set
CONFIG_SECTION_MISMATCH_WARN_ONLY=yto allow them.Change it to
__ro_after_initto prevent it from getting freed.Fixes cf9eca90a3397 ("fs/proc: Add /proc/cmdline_load for boot loader arguments")Signed-off-by Arnd Bergmann <[email protected]>--- include/linux/init.h | 2 +- init/main.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)include/linux/init.h +1
-1@@ -143,7 +143,7 @@ struct file_system_type;/* Defined in init/main.c */ extern int do_one_initcall (initcall_t fn); -extern char __initdata boot_command_line[]; +extern char boot_command_line[];extern char *saved_command_line;extern unsigned int saved_command_line_len;extern unsigned int reset_devices;init/main.c +1
-2@@ -135,7 +135,7 @@ EXPORT_SYMBOL(system_state);void (*__initdata late_time_init)(void );/* Untouched command line saved by arch-specific code. */ -char __initdata boot_command_line[COMMAND_LINE_SIZE ]; +char boot_command_line[COMMAND_LINE_SIZE ]__ro_after_init ;/* Untouched saved command line (eg. for /proc) */ char *saved_command_line__ro_after_init ;unsigned int saved_command_line_len__ro_after_init ; --2.39.2
Signature · 2 lines
Thanks, ~Nick Desaulniers
Quoted 4 lines · Nick Desaulniers
Quoted 3 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
Quoted 8 lines
Quoted 4 lines
The boot command line is not available after the init section gets discarded, so adding a permanent reference to it causes a link time warning:
WARNING: modpost: vmlinux: section mismatch in reference:
cmdline_load_proc_show+0x2(section: .text) ->boot_command_line(section: .init.data)
cmdline_load_proc_showis probably inlined, but should it also be marked__init? It's lone call site seems to be__initAFAICT.
No, that's not what it does: cmdline_load_proc_show() is called when someone reads /proc/cmdline_load from userspace. It's only the function that creates this procfs file that is __init, but the call happens later.
Arnd
Paul E. McKenney
Reviewed-by Nick DesaulniersQuoted 10 lines · Arnd Bergmann
Quoted 9 lines · Nick Desaulniers
Quoted 7 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
The boot command line is not available after the init section gets discarded, so adding a permanent reference to it causes a link time warning:
WARNING: modpost: vmlinux: section mismatch in reference:
cmdline_load_proc_show+0x2(section: .text) ->boot_command_line(section: .init.data)
Quoted 8 lines
Quoted 3 lines
cmdline_load_proc_showis probably inlined, but should it also be marked__init? It's lone call site seems to be__initAFAICT.No, that's not what it does:
cmdline_load_proc_show()is called when someone reads/proc/cmdline_loadfrom userspace. It's only the function that creates this procfs file that is__init, but the call happens later.
Thank you all! I have declared a tie between Stephen Rothwell and Arnd Bergmann for this fix. Please let me know if you are uncomfortable with these changes being squashed into the original with your guys' Co-developed-by. I also added Nick's Reviewed-by, please see below.
Thanx, Paul
------------------------------------------------------------------------
commit de2f542cfbec295ac0f9b6a832d7b3ba20df391f
Author: Paul E. McKenney <[email protected]> Date: Fri Jul 21 16:05:38 2023 -0700
fs/proc: Add /proc/cmdline_load for boot loader arguments
In kernels built with CONFIG_BOOT_CONFIG_FORCE=y, /proc/cmdline will show all kernel boot parameters, both those supplied by the boot loader and those embedded in the kernel image. This works well for those who just want to see all of the kernel boot parameters, but is not helpful to those who need to see only those parameters supplied by the boot loader. This is especially important when these parameters are presented to the boot loader by automation that might gather them from diverse sources.
Therefore, provide a /proc/cmdline_load file that shows only those kernel boot parameters supplied by the boot loader.
Why put this in /proc? Because it is quite similar to /proc/cmdline, so it makes sense to put it in the same place that /proc/cmdline is located.
fs/proc/cmdline.c +13 -0
@@ -3,6 +3,7 @@#include <linux/init.h> #include <linux/proc_fs.h> #include <linux/seq_file.h> +#include <asm/setup.h> #include "internal.h" static int cmdline_proc_show (struct seq_file *m,void *v)
@@ -12,6 +13,13 @@ static int cmdline_proc_show(struct seq_file *m, void *v)return 0 ; } +static int cmdline_load_proc_show (struct seq_file *m,void *v) +{ +seq_puts (m, boot_command_line); +seq_putc (m,'\n' ); +return 0 ; +} +static int __init proc_cmdline_init (void ) {struct proc_dir_entry *pde;
@@ -19,6 +27,11 @@ static int __init proc_cmdline_init(void) pde =proc_create_single ("cmdline" ,0 ,NULL , cmdline_proc_show);pde_make_permanent (pde); pde->size = saved_command_line_len +1 ; +if (IS_ENABLED (CONFIG_BOOT_CONFIG_FORCE )) { + pde =proc_create_single ("cmdline_load" ,0 ,NULL , cmdline_load_proc_show); +pde_make_permanent (pde); + pde->size =strnlen (boot_command_line,COMMAND_LINE_SIZE ) +1 ; + }return 0 ; }fs_initcall (proc_cmdline_init);
include/linux/init.h +4 -1
@@ -112,6 +112,9 @@#define __REFCONST .section ".ref.rodata", "a"#ifndef __ASSEMBLY__ + +#include <linux/cache.h> +/* * Used for initialization calls.. */
@@ -143,7 +146,7 @@ struct file_system_type;/* Defined in init/main.c */ extern int do_one_initcall (initcall_t fn); -extern char __initdata boot_command_line[]; +extern char boot_command_line[]__ro_after_init ;extern char *saved_command_line;extern unsigned int saved_command_line_len;extern unsigned int reset_devices;
init/main.c +1 -1
@@ -135,7 +135,7 @@ EXPORT_SYMBOL(system_state);void (*__initdata late_time_init)(void );/* Untouched command line saved by arch-specific code. */ -char __initdata boot_command_line[COMMAND_LINE_SIZE ]; +char boot_command_line[COMMAND_LINE_SIZE ]__ro_after_init ;/* Untouched saved command line (eg. for /proc) */ char *saved_command_line__ro_after_init ;unsigned int saved_command_line_len__ro_after_init ;