powerpc: convert to generic builtin command line
PATCH 2/3 powerpc: convert to generic builtin command line
This updates the powerpc code to use the CONFIG_GENERIC_CMDLINE option.
[[email protected]: add strlcat to prom_init_check.sh whitelist]
--- arch/powerpc/Kconfig | 23 +---------------------- arch/powerpc/kernel/prom.c | 4 ++++ arch/powerpc/kernel/prom_init.c | 8 ++++---- arch/powerpc/kernel/prom_init_check.sh | 2 +- 4 files changed, 10 insertions(+), 27 deletions(-)
arch/powerpc/Kconfig +1 -22
@@ -172,6 +172,7 @@ config PPC select GENERIC_STRNCPY_FROM_USER select GENERIC_STRNLEN_USER select GENERIC_TIME_VSYSCALL + select GENERIC_CMDLINE select HAVE_ARCH_AUDITSYSCALL select HAVE_ARCH_JUMP_LABEL select HAVE_ARCH_KGDB
@@ -777,28 +778,6 @@ config PPC_DENORMALISATION Add support for handling denormalisation of single precision values. Useful for bare metal only. If unsure say Y here. -config CMDLINE_BOOL - bool "Default bootloader kernel arguments" - -config CMDLINE - string "Initial kernel command string" - depends on CMDLINE_BOOL - default "console=ttyS0,9600 console=tty0 root=/dev/sda2" - help - On some platforms, there is currently no way for the boot loader to - pass arguments to the kernel. For these platforms, you can supply - some command-line options at build time by entering them here. In - most cases you will need to specify the root device here. - -config CMDLINE_FORCE - bool "Always use the default kernel command string" - depends on CMDLINE_BOOL - help - Always use the default kernel command string, even if the boot - loader passes other arguments to the kernel. - This is useful if you cannot or don't want to change the - command-line options your boot loader passes to the kernel. - config EXTRA_TARGETS string "Additional default image types" help
arch/powerpc/kernel/prom.c +4 -0
@@ -34,6 +34,7 @@#include <linux/of_fdt.h> #include <linux/libfdt.h> #include <linux/cpu.h> +#include <linux/cmdline.h> #include <asm/prom.h> #include <asm/rtas.h>
@@ -716,6 +717,9 @@ void __init early_init_devtree(void *params)*/ of_scan_flat_dt (early_init_dt_scan_chosen_ppc, boot_command_line); +/* append and prepend any arguments built into the kernel. */ +cmdline_add_builtin (boot_command_line,NULL ,COMMAND_LINE_SIZE ); +/* Scan memory nodes and rebuild MEMBLOCKs */ of_scan_flat_dt (early_init_dt_scan_root,NULL );of_scan_flat_dt (early_init_dt_scan_memory_ppc,NULL );
arch/powerpc/kernel/prom_init.c +4 -4
@@ -30,6 +30,7 @@#include <linux/delay.h> #include <linux/initrd.h> #include <linux/bitops.h> +#include <linux/cmdline.h> #include <asm/prom.h> #include <asm/rtas.h> #include <asm/page.h>
@@ -637,11 +638,10 @@ static void __init early_cmdline_parse(void) p = prom_cmd_line;if ((long )prom.chosen >0 ) l =prom_getprop (prom.chosen,"bootargs" , p,COMMAND_LINE_SIZE -1 ); -#ifdef CONFIG_CMDLINE +if (l <=0 || p[0 ] =='\0' )/* dbl check */ -strlcpy (prom_cmd_line, -CONFIG_CMDLINE ,sizeof (prom_cmd_line)); -#endif /* CONFIG_CMDLINE */ +cmdline_add_builtin_section (prom_cmd_line,NULL ,sizeof (prom_cmd_line), __prombss); +prom_printf ("command line: %s\n" , prom_cmd_line);#ifdef CONFIG_PPC64
arch/powerpc/kernel/prom_init_check.sh +1 -1
@@ -18,7 +18,7 @@ WHITELIST="add_reloc_offset __bss_start __bss_stop copy_and_flush _end enter_prom memcpy memset reloc_offset __secondary_hold -__secondary_hold_acknowledge __secondary_hold_spinloop __start +__secondary_hold_acknowledge __secondary_hold_spinloop __start strlcat strcmp strcpy strlcpy strlen strncmp strstr kstrtobool logo_linux_clut224 reloc_got2 kernstart_addr memstart_addr linux_banner _stext __prom_init_toc_start __prom_init_toc_end btext_setup_display TOC."
Signature · 1 line
2.14.1
Le 01/03/2019 à 20:44, Daniel Walker a écrit :
Quoted 2 lines
This updates the powerpc code to use the
CONFIG_GENERIC_CMDLINEoption.
Please explain more in details how each powerpc option is replaced by one of the generic options.
Quoted 69 lines
[[email protected]: add strlcat to
prom_init_check.shwhitelist]Cc Daniel Walker <[email protected]>Cc Daniel Walker <[email protected]>Signed-off-by Daniel Walker <[email protected]>Signed-off-by Maksym Kokhan <[email protected]>--- arch/powerpc/Kconfig | 23 +---------------------- arch/powerpc/kernel/prom.c | 4 ++++ arch/powerpc/kernel/prom_init.c | 8 ++++---- arch/powerpc/kernel/prom_init_check.sh | 2 +- 4 files changed, 10 insertions(+), 27 deletions(-)arch/powerpc/Kconfig +1
-22@@ -172,6 +172,7 @@ config PPC select GENERIC_STRNCPY_FROM_USER select GENERIC_STRNLEN_USER select GENERIC_TIME_VSYSCALL + select GENERIC_CMDLINE select HAVE_ARCH_AUDITSYSCALL select HAVE_ARCH_JUMP_LABEL select HAVE_ARCH_KGDB@@ -777,28 +778,6 @@ config PPC_DENORMALISATION Add support for handling denormalisation of single precision values. Useful for bare metal only. If unsure say Y here. -config CMDLINE_BOOL - bool "Default bootloader kernel arguments" - -config CMDLINE - string "Initial kernel command string" - depends on CMDLINE_BOOL - default "console=ttyS0,9600 console=tty0 root=/dev/sda2" - help - On some platforms, there is currently no way for the boot loader to - pass arguments to the kernel. For these platforms, you can supply - some command-line options at build time by entering them here. In - most cases you will need to specify the root device here. - -config CMDLINE_FORCE - bool "Always use the default kernel command string" - depends on CMDLINE_BOOL - help - Always use the default kernel command string, even if the boot - loader passes other arguments to the kernel. - This is useful if you cannot or don't want to change the - command-line options your boot loader passes to the kernel. - config EXTRA_TARGETS string "Additional default image types" helparch/powerpc/kernel/prom.c +1
-0@@ -34,6 +34,7 @@#include <linux/of_fdt.h> #include <linux/libfdt.h> #include <linux/cpu.h> +#include <linux/cmdline.h> #include <asm/prom.h> #include <asm/rtas.h>
arch/powerpc/kernel/prom.c void __init early_init_devtree(void *params) · line 722
Quoted 6 lines
arch/powerpc/kernel/prom.c +3
-0@@ -716,6 +717,9 @@ void __init early_init_devtree(void *params)*/ of_scan_flat_dt (early_init_dt_scan_chosen_ppc, boot_command_line); +/* append and prepend any arguments built into the kernel. */ +cmdline_add_builtin (boot_command_line,NULL ,COMMAND_LINE_SIZE ); +
I don't think it is worth an implementation as complex as in the previous patch just for the above line. Could easily define the temporary buffer in this file directely, then just locally do:
strlcpy(temp_buff, CONFIG_CMDLINE_PREPEND, COMMAND_LINE_SIZE); strlcat(temp_buff, boot_command_line, COMMAND_LINE_SIZE); strlcat(temp_buff, CONFIG_CMDLINE_APPEND, COMMAND_LINE_SIZE); strlcpy(boot_command_line, temp_buff, COMMAND_LINE_SIZE);
Quoted 17 lines
arch/powerpc/kernel/prom.c +0
-0/* Scan memory nodes and rebuild MEMBLOCKs */ of_scan_flat_dt (early_init_dt_scan_root,NULL );of_scan_flat_dt (early_init_dt_scan_memory_ppc,NULL );arch/powerpc/kernel/prom_init.c +1
-0@@ -30,6 +30,7 @@#include <linux/delay.h> #include <linux/initrd.h> #include <linux/bitops.h> +#include <linux/cmdline.h> #include <asm/prom.h> #include <asm/rtas.h> #include <asm/page.h> @@ -637,11 +638,10 @@ static void __init early_cmdline_parse(void) p = prom_cmd_line;
arch/powerpc/kernel/prom_init.c static void __init early_cmdline_parse(void) · line 644
Quoted 10 lines
arch/powerpc/kernel/prom_init.c +3
-4if ((long )prom.chosen >0 ) l =prom_getprop (prom.chosen,"bootargs" , p,COMMAND_LINE_SIZE -1 ); -#ifdef CONFIG_CMDLINE +if (l <=0 || p[0 ] =='\0' )/* dbl check */ -strlcpy (prom_cmd_line, -CONFIG_CMDLINE ,sizeof (prom_cmd_line)); -#endif /* CONFIG_CMDLINE */ +cmdline_add_builtin_section (prom_cmd_line,NULL ,sizeof (prom_cmd_line), __prombss); +
You don't need something as complex as what your generic code does for that. It could be done with the following simple line:
strlcpy(prom_cmd_line, CONFIG_CMDLINE_PREPEND " " CONFIG_CMDLINE_APPEND, sizeof(prom_cmd_line));
arch/powerpc/kernel/prom_init_check.sh line 21
Quoted 13 lines
arch/powerpc/kernel/prom_init.c +0
-0prom_printf ("command line: %s\n" , prom_cmd_line);#ifdef CONFIG_PPC64 arch/powerpc/kernel/prom_init_check.sh +1
-1@@ -18,7 +18,7 @@ WHITELIST="add_reloc_offset __bss_start __bss_stop copy_and_flush _end enter_prom memcpy memset reloc_offset __secondary_hold -__secondary_hold_acknowledge __secondary_hold_spinloop __start +__secondary_hold_acknowledge __secondary_hold_spinloop __start strlcat
The above is a big issue. In the scope of KASAN implementation, we are getting rid of generic string functions from prom_init because they are KASAN instrumented and that's far too early for prom_init. See series https://patchwork.ozlabs.org/project/linuxppc-dev/list/?series=94949 and especially patch [v9,03/11] powerpc/prom_init: don't use string functions from lib/
arch/powerpc/kernel/prom_init_check.sh line 24
Quoted 4 lines
arch/powerpc/kernel/prom_init_check.sh +0
-0strcmp strcpy strlcpy strlen strncmp strstr kstrtobool logo_linux_clut224 reloc_got2 kernstart_addr memstart_addr linux_banner _stext __prom_init_toc_start __prom_init_toc_end btext_setup_display TOC."
Thanks
Christophe
Le 04/03/2019 à 15:26, Christophe Leroy a écrit :
Quoted 85 lines
Le 01/03/2019 à 20:44, Daniel Walker a écrit :
Quoted 2 lines
This updates the powerpc code to use the
CONFIG_GENERIC_CMDLINEoption.Please explain more in details how each powerpc option is replaced by one of the generic options.
Quoted 68 lines
[[email protected]: add strlcat to
prom_init_check.shwhitelist]Cc Daniel Walker <[email protected]>Cc Daniel Walker <[email protected]>Signed-off-by Daniel Walker <[email protected]>Signed-off-by Maksym Kokhan <[email protected]>---
arch/powerpc/Kconfig | 23 +---------------------- arch/powerpc/kernel/prom.c | 4 ++++ arch/powerpc/kernel/prom_init.c | 8 ++++----arch/powerpc/kernel/prom_init_check.sh| 2 +-4 files changed, 10 insertions(+), 27 deletions(-)arch/powerpc/Kconfig +0
-0@@ -172,6 +172,7 @@ config PPCselect
GENERIC_STRNCPY_FROM_USER
selectGENERIC_STRNLEN_USER
selectGENERIC_TIME_VSYSCALL
+ selectGENERIC_CMDLINE
selectHAVE_ARCH_AUDITSYSCALL
selectHAVE_ARCH_JUMP_LABEL
selectHAVE_ARCH_KGDBarch/powerpc/Kconfig +0
-0@@ -777,28 +778,6 @@ config PPC_DENORMALISATIONAdd support for handling denormalisation of single precision values. Useful for bare metal only. If unsure say Y here.
arch/powerpc/Kconfig +0
-9-config CMDLINE_BOOL - bool "Default bootloader kernel arguments" - -config CMDLINE - string "Initial kernel command string" - depends on CMDLINE_BOOL - default "console=ttyS0,9600 console=tty0 root=/dev/sda2" - help - On some platforms, there is currently no way for the bootloader to
- pass arguments to the kernel. For these platforms, you can supply - some command-line options at build time by entering them here. In - most cases you will need to specify the root device here.arch/powerpc/Kconfig +0
-10- -config CMDLINE_FORCE - bool "Always use the default kernel command string" - depends on CMDLINE_BOOL - help - Always use the default kernel command string, even if the boot - loader passes other arguments to the kernel. - This is useful if you cannot or don't want to change the - command-line options your boot loader passes to the kernel. -config
EXTRA_TARGETS
string "Additional default image types"
helparch/powerpc/kernel/prom.c +1
-0@@ -34,6 +34,7 @@ #include <linux/of_fdt.h> #include <linux/libfdt.h> #include <linux/cpu.h> +#include <linux/cmdline.h> #include <asm/prom.h> #include <asm/rtas.h>arch/powerpc/kernel/prom.c void __init early_init_devtree(void *params) · line 721
Quoted 5 lines
arch/powerpc/kernel/prom.c +3
-0@@ -716,6 +717,9 @@ void __init early_init_devtree(void *params)*/ of_scan_flat_dt(early_init_dt_scan_chosen_ppc, boot_command_line); + /* append and prepend any arguments built into the kernel. */ + cmdline_add_builtin(boot_command_line, NULL, COMMAND_LINE_SIZE); +I don't think it is worth an implementation as complex as in the previous patch just for the above line. Could easily define the temporary buffer in this file directely, then just locally do:
Quoted 4 lines
strlcpy(temp_buff, CONFIG_CMDLINE_PREPEND, COMMAND_LINE_SIZE);strlcat(temp_buff, boot_command_line, COMMAND_LINE_SIZE);strlcat(temp_buff, CONFIG_CMDLINE_APPEND, COMMAND_LINE_SIZE);strlcpy(boot_command_line, temp_buff, COMMAND_LINE_SIZE);
And in fact, what should really be done is not the above but simply update early_init_dt_scan_chosen_ppc() in drivers/of/fdt.c as it is there that CONFIG_CMDLINE and CONFIG_CMDLINE_FORCE and CONFIG_CMDLINE_EXTEND are handled.
It looks to me that the current implementation is rather complete and eventually only missing the prepend. Why not just add prepend to the current implementation, and also move CONFIG_CMDLINE etc ... into arch/Kconfig instead of having it in each arch ?
Christophe
Quoted 57 lines
Quoted 24 lines
arch/powerpc/kernel/prom.c +0
-0/* Scan memory nodes and rebuild MEMBLOCKs */ of_scan_flat_dt(early_init_dt_scan_root, NULL); of_scan_flat_dt(early_init_dt_scan_memory_ppc, NULL);arch/powerpc/kernel/prom_init.c +2
-1@@ -30,6 +30,7 @@ #include <linux/delay.h> #include <linux/initrd.h> #include <linux/bitops.h> +#include <linux/cmdline.h> #include <asm/prom.h> #include <asm/rtas.h> #include <asm/page.h>@@ -637,11 +638,10 @@ static void __init early_cmdline_parse(void) p = prom_cmd_line; if ((long)prom.chosen > 0) l = prom_getprop(prom.chosen, "bootargs", p, COMMAND_LINE_SIZE-1); -#ifdef CONFIG_CMDLINE +Quoted 7 lines
if (l <= 0 || p[0] == '\0') /* dbl check */ - strlcpy(prom_cmd_line,
-CONFIG_CMDLINE,sizeof(prom_cmd_line)); -#endif /*CONFIG_CMDLINE*/
+cmdline_add_builtin_section(prom_cmd_line, NULL, sizeof(prom_cmd_line), __prombss);
+You don't need something as complex as what your generic code does for that. It could be done with the following simple line:
strlcpy(prom_cmd_line, CONFIG_CMDLINE_PREPEND " " CONFIG_CMDLINE_APPEND, sizeof(prom_cmd_line));arch/powerpc/kernel/prom_init_check.sh line 21
Quoted 11 lines
prom_printf("command line: %s\n", prom_cmd_line); #ifdefCONFIG_PPC64arch/powerpc/kernel/prom_init_check.sh +0
-0@@ -18,7 +18,7 @@WHITELIST="add_reloc_offset
__bss_start__bss_stopcopy_and_flush_endenter_prommemcpy memsetreloc_offset__secondary_holdarch/powerpc/kernel/prom_init_check.sh +1
-1-__secondary_hold_acknowledge __secondary_hold_spinloop __start +__secondary_hold_acknowledge __secondary_hold_spinloop __start strlcatThe above is a big issue. In the scope of KASAN implementation, we are getting rid of generic string functions from
prom_initbecause they are KASAN instrumented and that's far too early forprom_init. See series https://patchwork.ozlabs.org/project/linuxppc-dev/list/?series=94949 and especially patch [v9,03/11] powerpc/prom_init: don't use string functions fromlib/Quoted 4 lines
strcmp strcpy strlcpy strlen strncmp strstr kstrtobool
logo_linux_clut224reloc_got2kernstart_addrmemstart_addrlinux_banner_stext__prom_init_toc_start__prom_init_toc_endbtext_setup_displayTOC."Thanks
Christophe
Quoted 8 lines · Christophe Leroy
Le 01/03/2019 à 20:44, Daniel Walker a écrit :
Quoted 2 lines
This updates the powerpc code to use the
CONFIG_GENERIC_CMDLINEoption.Please explain more in details how each powerpc option is replaced by one of the generic options.
CMDLINE is replace by two options to either which allow static options to either be appended or prepended to the boot loader arguemnts. If you wanted a lateral changes you would only fill in CONFIG_CMDLINE_PREPEND. CONFIG_CMDLINE_OVERRIDE does the same as CMDLINE_FORCE, only with the append and prepend arguemnts merged without the boot loader arguments.
Quoted 21 lines
Quoted 10 lines
arch/powerpc/kernel/prom.c +1
-0@@ -34,6 +34,7 @@#include <linux/of_fdt.h> #include <linux/libfdt.h> #include <linux/cpu.h> +#include <linux/cmdline.h> #include <asm/prom.h> #include <asm/rtas.h> arch/powerpc/kernel/prom.c void __init early_init_devtree(void *params) · line 721
Quoted 5 lines
arch/powerpc/kernel/prom.c +3
-0@@ -716,6 +717,9 @@ void __init early_init_devtree(void *params)*/ of_scan_flat_dt (early_init_dt_scan_chosen_ppc, boot_command_line); +/* append and prepend any arguments built into the kernel. */ +cmdline_add_builtin (boot_command_line,NULL ,COMMAND_LINE_SIZE ); +I don't think it is worth an implementation as complex as in the previous patch just for the above line.
Could easily define the temporary buffer in this file directely, then just locally do:
Quoted 4 lines
strlcpy(temp_buff, CONFIG_CMDLINE_PREPEND, COMMAND_LINE_SIZE);strlcat(temp_buff, boot_command_line, COMMAND_LINE_SIZE);strlcat(temp_buff, CONFIG_CMDLINE_APPEND, COMMAND_LINE_SIZE);strlcpy(boot_command_line, temp_buff, COMMAND_LINE_SIZE);
The point of the code is to have an implementation that other architecture can use. If we open code it in powerpc we're no better off.
Quoted 46 lines
Quoted 19 lines
arch/powerpc/kernel/prom.c +0
-0/* Scan memory nodes and rebuild MEMBLOCKs */ of_scan_flat_dt (early_init_dt_scan_root,NULL );of_scan_flat_dt (early_init_dt_scan_memory_ppc,NULL );arch/powerpc/kernel/prom_init.c +1
-0@@ -30,6 +30,7 @@#include <linux/delay.h> #include <linux/initrd.h> #include <linux/bitops.h> +#include <linux/cmdline.h> #include <asm/prom.h> #include <asm/rtas.h> #include <asm/page.h> @@ -637,11 +638,10 @@ static void __init early_cmdline_parse(void) p = prom_cmd_line;arch/powerpc/kernel/prom_init.c static void __init early_cmdline_parse(void) · line 644
Quoted 10 lines
arch/powerpc/kernel/prom_init.c +3
-4if ((long )prom.chosen >0 ) l =prom_getprop (prom.chosen,"bootargs" , p,COMMAND_LINE_SIZE -1 ); -#ifdef CONFIG_CMDLINE +if (l <=0 || p[0 ] =='\0' )/* dbl check */ -strlcpy (prom_cmd_line, -CONFIG_CMDLINE ,sizeof (prom_cmd_line)); -#endif /* CONFIG_CMDLINE */ +cmdline_add_builtin_section (prom_cmd_line,NULL ,sizeof (prom_cmd_line), __prombss); +You don't need something as complex as what your generic code does for that. It could be done with the following simple line:
strlcpy(prom_cmd_line, CONFIG_CMDLINE_PREPEND " " CONFIG_CMDLINE_APPEND, sizeof(prom_cmd_line));Quoted 10 lines
arch/powerpc/kernel/prom_init.c +0
-0prom_printf ("command line: %s\n" , prom_cmd_line);#ifdef CONFIG_PPC64 arch/powerpc/kernel/prom_init_check.sh +0
-1@@ -18,7 +18,7 @@ WHITELIST="add_reloc_offset __bss_start __bss_stop copy_and_flush _end enter_prom memcpy memset reloc_offset __secondary_hold -__secondary_hold_acknowledge __secondary_hold_spinloop __start
Quoted 8 lines
arch/powerpc/kernel/prom_init_check.sh line 21
Quoted 1 line
arch/powerpc/kernel/prom_init_check.sh +1
-0+__secondary_hold_acknowledge __secondary_hold_spinloop __start strlcatThe above is a big issue. In the scope of KASAN implementation, we are getting rid of generic string functions from
prom_initbecause they are KASAN instrumented and that's far too early forprom_init. See series
https://patchwork.ozlabs.org/project/linuxppc-dev/list/?series=94949 and especially patch [v9,03/11] powerpc/prom_init: don't use string functions fromlib/
You already re-implemented a number of string functions, seem easy enough to add another one.
What your doing here is exactly what I'm trying to prevent in my implementation. Say there is a small, but horrific defect in one of the string functions. Some other architecture fixes it in lib/strings.c , woops , you just missed it and now prom_init.c is stuck with it unless powerpc maintainers are watching closely to keep up with the fixes to the string functions.
You could move these functions into the include/linux/string.h as static inlines, then use them in lib/strings.c and in prom_init.c. Then you have a unified implementation. I assume you would regard that as ugly tho.
Something else you would regard as ugly , your not adding an #ifdef on KASAN in prom_init.c for the string functions. If you have that then any buggy string functions which you may add (or forget to update) would only cause problems if you had KASAN enabled. That then isolates any problems you cause to only debug kernels with KASAN enabled, instead of unilaterally all platforms which use prom_init.c. That would also only increase the size if KASAN is enabled. Very desirable, but ugly. I think most of us kernel hackers will take the ugly.
#ifdef CONFIG_KASAN
...
#else
#define prom_strcmp strcmp
...
#endif /* !CONFIG_KASAN */
(you would have to change arch/powerpc/kernel/prom_init_check.sh , but that shouldn't be too hard)
Daniel