[PATCH 7/8] of: allow sending a NULL value to early_init_dt_scan_chosen

2021-04-15 Thread Daniel Walker
It's possible that an architecture may want to populate
boot_command_line before calling the device tree code.
Currently, early_init_dt_scan_chosen won't accept a NULL
in the data parameter and it returns immediately if you
send one.

I changed early_init_dt_scan_nodes() to send a NULL into
early_init_dt_scan_chosen() , then I made
early_init_dt_scan_chosen() to do the initrd checking, and
the rng-seed checking and skip all the command line related
code.

Given lots of changes to the command line, I think it makes sense
to allow the initrd code and rng-seed code to be run without
forcing the command line handling. I'm also submitting changes
to arm64 which populate boot_command_line much early and this
device tree code overwrites boot_command_line in that case.

This code depends on all architecture to have a NULL
boot_command_line at boot up when this function runs, unless
it's already populated.

This code was boot tested on powerpc 32bit, x86, and arm64.

Cc: xe-linux-exter...@cisco.com
Signed-off-by: Daniel Walker 
---
 drivers/of/fdt.c | 44 +---
 1 file changed, 25 insertions(+), 19 deletions(-)

diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index adb26aff481d..a1fda952ce60 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -1052,36 +1052,38 @@ int __init early_init_dt_scan_chosen(unsigned long 
node, const char *uname,
 
pr_debug("search \"chosen\", depth: %d, uname: %s\n", depth, uname);
 
-   if (depth != 1 || !data ||
-   (strcmp(uname, "chosen") != 0 && strcmp(uname, "chosen@0") != 0))
+   if (depth != 1 || (strcmp(uname, "chosen") != 0
+   && strcmp(uname, "chosen@0") != 0))
return 0;
 
early_init_dt_check_for_initrd(node);
 
-   /* Retrieve command line */
-   p = of_get_flat_dt_prop(node, "bootargs", );
-   if (p != NULL && l > 0)
-   strlcpy(data, p, min(l, COMMAND_LINE_SIZE));
+   if (data) {
+   /* Retrieve command line */
+   p = of_get_flat_dt_prop(node, "bootargs", );
+   if (p != NULL && l > 0)
+   strlcpy(data, p, min(l, COMMAND_LINE_SIZE));
 
-   /*
-* CONFIG_CMDLINE is meant to be a default in case nothing else
-* managed to set the command line, unless CONFIG_CMDLINE_FORCE
-* is set in which case we override whatever was found earlier.
-*/
+   /*
+* CONFIG_CMDLINE is meant to be a default in case nothing else
+* managed to set the command line, unless CONFIG_CMDLINE_FORCE
+* is set in which case we override whatever was found earlier.
+*/
 #ifdef CONFIG_CMDLINE
 #if defined(CONFIG_CMDLINE_EXTEND)
-   strlcat(data, " ", COMMAND_LINE_SIZE);
-   strlcat(data, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
+   strlcat(data, " ", COMMAND_LINE_SIZE);
+   strlcat(data, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
 #elif defined(CONFIG_CMDLINE_FORCE)
-   strlcpy(data, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
-#else
-   /* No arguments from boot loader, use kernel's  cmdl*/
-   if (!((char *)data)[0])
strlcpy(data, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
+#else
+   /* No arguments from boot loader, use kernel's  cmdl*/
+   if (!((char *)data)[0])
+   strlcpy(data, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
 #endif
 #endif /* CONFIG_CMDLINE */
 
-   pr_debug("Command line is: %s\n", (char *)data);
+   pr_debug("Command line is: %s\n", (char *)data);
+   }
 
rng_seed = of_get_flat_dt_prop(node, "rng-seed", );
if (rng_seed && l > 0) {
@@ -1202,7 +1204,11 @@ void __init early_init_dt_scan_nodes(void)
int rc = 0;
 
/* Retrieve various information from the /chosen node */
-   rc = of_scan_flat_dt(early_init_dt_scan_chosen, boot_command_line);
+   if (boot_command_line[0])
+   rc = of_scan_flat_dt(early_init_dt_scan_chosen, NULL);
+   else
+   rc = of_scan_flat_dt(early_init_dt_scan_chosen,
+   boot_command_line);
if (!rc)
pr_warn("No chosen node found, continuing without\n");
 
-- 
2.25.1



[PATCH 5/8] drivers: firmware: efi: libstub: enable generic commandline

2021-04-15 Thread Daniel Walker
This adds code to handle the generic command line changes.
The efi code appears that it doesn't benefit as much from this design
as it could.

For example, if you had a prepend command line with "nokaslr" then
you might be helpful to re-enable it in the boot loader or dts,
but there appears to be no way to re-enable kaslr or some of the
other options.

The efi command line handling is incorrect. x86 and arm have an append
system however the efi code prepends the command line.

For example, you could have a non-upgradable bios which sends

efi=disable_early_pci_dma

This hypothetically could have been set because early pci dma caused
issues on early versions of the product.

Then later the early pci dma was made to work and the company desired
to start using it. To override the bios you could set the CONFIG_CMDLINE
to,

efi=no_disable_early_pci_dma

then parsing would normally start with the bios command line, then move
to the CONFIG_CMDLINE and you would end up with early pci dma turned on.

however, current efi code keeps early pci dma off because the bios
arguments always override the built in.

Per my reading this is different from the main body of x86, arm, and
arm64.

The generic command line provides both append and prepend, so it
alleviates this issue if it's used. However not all architectures use
it.

It would be desirable to allow the efi stub to have it's builtin command
line to be modified after compile, but I don't see a feasible way to do
that currently.

Cc: xe-linux-exter...@cisco.com
Signed-off-by: Daniel Walker 
---
 .../firmware/efi/libstub/efi-stub-helper.c| 29 +++
 drivers/firmware/efi/libstub/efi-stub.c   |  9 ++
 drivers/firmware/efi/libstub/efistub.h|  1 +
 drivers/firmware/efi/libstub/x86-stub.c   | 13 +++--
 4 files changed, 50 insertions(+), 2 deletions(-)

diff --git a/drivers/firmware/efi/libstub/efi-stub-helper.c 
b/drivers/firmware/efi/libstub/efi-stub-helper.c
index aa8da0a49829..16318f55f187 100644
--- a/drivers/firmware/efi/libstub/efi-stub-helper.c
+++ b/drivers/firmware/efi/libstub/efi-stub-helper.c
@@ -13,6 +13,7 @@
 #include 
 #include 
 #include  /* For CONSOLE_LOGLEVEL_* */
+#include 
 #include 
 #include 
 
@@ -172,6 +173,34 @@ int efi_printk(const char *fmt, ...)
return printed;
 }
 
+/**
+ * efi_handle_cmdline() - handle adding in building parts of the command line
+ * @cmdline:   kernel command line
+ *
+ * Add in the generic parts of the commandline and start the parsing of the
+ * command line.
+ *
+ * Return: status code
+ */
+efi_status_t efi_handle_cmdline(char const *cmdline)
+{
+   efi_status_t status = EFI_SUCCESS;
+
+   if (sizeof(CMDLINE_STATIC_PREPEND) > 1)
+   status |= efi_parse_options(CMDLINE_STATIC_PREPEND);
+
+   if (!IS_ENABLED(CONFIG_CMDLINE_OVERRIDE))
+   status |= efi_parse_options(cmdline);
+
+   if (sizeof(CMDLINE_STATIC_APPEND) > 1)
+   status |= efi_parse_options(CMDLINE_STATIC_APPEND);
+
+   if (status != EFI_SUCCESS)
+   efi_err("Failed to parse options\n");
+
+   return status;
+}
+
 /**
  * efi_parse_options() - Parse EFI command line options
  * @cmdline:   kernel command line
diff --git a/drivers/firmware/efi/libstub/efi-stub.c 
b/drivers/firmware/efi/libstub/efi-stub.c
index 26e69788f27a..baa69b24cfdd 100644
--- a/drivers/firmware/efi/libstub/efi-stub.c
+++ b/drivers/firmware/efi/libstub/efi-stub.c
@@ -172,6 +172,14 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
goto fail;
}
 
+#ifdef CONFIG_GENERIC_CMDLINE
+   status = efi_handle_cmdline(cmdline_ptr);
+   if (status != EFI_SUCCESS) {
+   goto fail_free_cmdline;
+   }
+#endif
+
+#ifdef CONFIG_CMDLINE
if (IS_ENABLED(CONFIG_CMDLINE_EXTEND) ||
IS_ENABLED(CONFIG_CMDLINE_FORCE) ||
cmdline_size == 0) {
@@ -189,6 +197,7 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
goto fail_free_cmdline;
}
}
+#endif
 
efi_info("Booting Linux Kernel...\n");
 
diff --git a/drivers/firmware/efi/libstub/efistub.h 
b/drivers/firmware/efi/libstub/efistub.h
index cde0a2ef507d..07c7f9fdfffc 100644
--- a/drivers/firmware/efi/libstub/efistub.h
+++ b/drivers/firmware/efi/libstub/efistub.h
@@ -800,6 +800,7 @@ efi_status_t efi_relocate_kernel(unsigned long *image_addr,
 unsigned long alignment,
 unsigned long min_addr);
 
+efi_status_t efi_handle_cmdline(char const *cmdline);
 efi_status_t efi_parse_options(char const *cmdline);
 
 void efi_parse_option_graphics(char *option);
diff --git a/drivers/firmware/efi/libstub/x86-stub.c 
b/drivers/firmware/efi/libstub/x86-stub.c
index f14c4ff5839f..30ad8fb7122d 100644
--- a/drivers/firmware/efi/libstub/x86-stub.c
+++ b/drivers/firmware/efi/libstub/x86-stub.c
@@ -673,6 +673,8 @@ unsign

[PATCH 8/8] CMDLINE: arm64: convert to generic builtin command line

2021-04-15 Thread Daniel Walker
This removes arm64 from the device tree handling of the
command line arguments.

The boot_command_line variable is populated inside the earliest
user of the command line, which is in idreg-override.c.

The device tree should not be needed to do any further handling
of the boot command line options.

Cc: xe-linux-exter...@cisco.com
Signed-off-by: Daniel Walker 
---
 arch/arm64/Kconfig | 33 +-
 arch/arm64/include/asm/setup.h |  2 ++
 arch/arm64/kernel/idreg-override.c |  9 
 3 files changed, 8 insertions(+), 36 deletions(-)

diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index e4e1b6550115..9781ba3758b1 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -105,6 +105,7 @@ config ARM64
select GENERIC_ALLOCATOR
select GENERIC_ARCH_TOPOLOGY
select GENERIC_CLOCKEVENTS_BROADCAST
+   select GENERIC_CMDLINE
select GENERIC_CPU_AUTOPROBE
select GENERIC_CPU_VULNERABILITIES
select GENERIC_EARLY_IOREMAP
@@ -1841,38 +1842,6 @@ config ARM64_ACPI_PARKING_PROTOCOL
  protocol even if the corresponding data is present in the ACPI
  MADT table.
 
-config CMDLINE
-   string "Default kernel command string"
-   default ""
-   help
- Provide a set of default command-line options at build time by
- entering them here. As a minimum, you should specify the the
- root device (e.g. root=/dev/nfs).
-
-choice
-   prompt "Kernel command line type" if CMDLINE != ""
-   default CMDLINE_FROM_BOOTLOADER
-   help
- Choose how the kernel will handle the provided default kernel
- command line string.
-
-config CMDLINE_FROM_BOOTLOADER
-   bool "Use bootloader kernel arguments if available"
-   help
- Uses the command-line options passed by the boot loader. If
- the boot loader doesn't provide any, the default kernel command
- string provided in CMDLINE will be used.
-
-config CMDLINE_FORCE
-   bool "Always use the default kernel command string"
-   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.
-
-endchoice
-
 config EFI_STUB
bool
 
diff --git a/arch/arm64/include/asm/setup.h b/arch/arm64/include/asm/setup.h
index d3320618ed14..1f5b6d8f2433 100644
--- a/arch/arm64/include/asm/setup.h
+++ b/arch/arm64/include/asm/setup.h
@@ -5,7 +5,9 @@
 
 #include 
 
+#ifndef __ASSEMBLY__
 void *get_early_fdt_ptr(void);
 void early_fdt_map(u64 dt_phys);
+#endif /* __ASSEMBLY__ */
 
 #endif
diff --git a/arch/arm64/kernel/idreg-override.c 
b/arch/arm64/kernel/idreg-override.c
index 83f1c4b92095..0a3fcae13043 100644
--- a/arch/arm64/kernel/idreg-override.c
+++ b/arch/arm64/kernel/idreg-override.c
@@ -9,6 +9,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -188,11 +189,11 @@ static __init void parse_cmdline(void)
 {
const u8 *prop = get_bootargs_cmdline();
 
-   if (IS_ENABLED(CONFIG_CMDLINE_FORCE) || !prop)
-   __parse_cmdline(CONFIG_CMDLINE, true);
+   strscpy(boot_command_line, prop, COMMAND_LINE_SIZE);
+   cmdline_add_builtin(boot_command_line);
+
+   __parse_cmdline(boot_command_line, true);
 
-   if (!IS_ENABLED(CONFIG_CMDLINE_FORCE) && prop)
-   __parse_cmdline(prop, true);
 }
 
 /* Keep checkers quiet */
-- 
2.25.1



[PATCH 6/8] CMDLINE: x86: convert to generic builtin command line

2021-04-15 Thread Daniel Walker
This updates the x86 code to use the CONFIG_GENERIC_CMDLINE
option.

Cc: xe-linux-exter...@cisco.com
Signed-off-by: Ruslan Ruslichenko 
Signed-off-by: Ruslan Bilovol 
Signed-off-by: Daniel Walker 
---
 arch/x86/Kconfig| 44 +
 arch/x86/kernel/setup.c | 18 ++---
 2 files changed, 3 insertions(+), 59 deletions(-)

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 2792879d398e..73ea9589e50d 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -118,6 +118,7 @@ config X86
select EDAC_SUPPORT
select GENERIC_CLOCKEVENTS_BROADCASTif X86_64 || (X86_32 && 
X86_LOCAL_APIC)
select GENERIC_CLOCKEVENTS_MIN_ADJUST
+   select GENERIC_CMDLINE
select GENERIC_CMOS_UPDATE
select GENERIC_CPU_AUTOPROBE
select GENERIC_CPU_VULNERABILITIES
@@ -2358,49 +2359,6 @@ choice
 
 endchoice
 
-config CMDLINE_BOOL
-   bool "Built-in kernel command line"
-   help
- Allow for specifying boot arguments to the kernel at
- build time.  On some systems (e.g. embedded ones), it is
- necessary or convenient to provide some or all of the
- kernel boot arguments with the kernel itself (that is,
- to not rely on the boot loader to provide them.)
-
- To compile command line arguments into the kernel,
- set this option to 'Y', then fill in the
- boot arguments in CONFIG_CMDLINE.
-
- Systems with fully functional boot loaders (i.e. non-embedded)
- should leave this option set to 'N'.
-
-config CMDLINE
-   string "Built-in kernel command string"
-   depends on CMDLINE_BOOL
-   default ""
-   help
- Enter arguments here that should be compiled into the kernel
- image and used at boot time.  If the boot loader provides a
- command line at boot time, it is appended to this string to
- form the full kernel command line, when the system boots.
-
- However, you can use the CONFIG_CMDLINE_OVERRIDE option to
- change this behavior.
-
- In most cases, the command line (whether built-in or provided
- by the boot loader) should specify the device for the root
- file system.
-
-config CMDLINE_OVERRIDE
-   bool "Built-in command line overrides boot loader arguments"
-   depends on CMDLINE_BOOL && CMDLINE != ""
-   help
- Set this option to 'Y' to have the kernel ignore the boot loader
- command line, and use ONLY the built-in command line.
-
- This is used to work around broken boot loaders.  This should
- be set to 'N' under normal conditions.
-
 config MODIFY_LDT_SYSCALL
bool "Enable the LDT (local descriptor table)" if EXPERT
default y
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index 5ecd69a48393..cd2aa33c44d7 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -47,6 +47,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /*
  * max_low_pfn_mapped: highest directly mapped pfn < 4 GB
@@ -161,9 +162,6 @@ unsigned long saved_video_mode;
 #define RAMDISK_LOAD_FLAG  0x4000
 
 static char __initdata command_line[COMMAND_LINE_SIZE];
-#ifdef CONFIG_CMDLINE_BOOL
-static char __initdata builtin_cmdline[COMMAND_LINE_SIZE] = CONFIG_CMDLINE;
-#endif
 
 #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
 struct edd edd;
@@ -883,19 +881,7 @@ void __init setup_arch(char **cmdline_p)
bss_resource.start = __pa_symbol(__bss_start);
bss_resource.end = __pa_symbol(__bss_stop)-1;
 
-#ifdef CONFIG_CMDLINE_BOOL
-#ifdef CONFIG_CMDLINE_OVERRIDE
-   strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
-#else
-   if (builtin_cmdline[0]) {
-   /* append boot loader cmdline to builtin */
-   strlcat(builtin_cmdline, " ", COMMAND_LINE_SIZE);
-   strlcat(builtin_cmdline, boot_command_line, COMMAND_LINE_SIZE);
-   strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
-   }
-#endif
-#endif
-
+   cmdline_add_builtin(boot_command_line);
strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
*cmdline_p = command_line;
 
-- 
2.25.1



[PATCH 4/8] CMDLINE: mips: convert to generic builtin command line

2021-04-15 Thread Daniel Walker
This updates the mips code to use the CONFIG_GENERIC_CMDLINE
option.

This deletes the option for MIPS_CMDLINE_BUILTIN_EXTEND
and replaces the functionality with generic code.

Of note, the pic32 has some strange handling of the current built
in command line. It was converted to use the static variant which
can't be updated after compilation. It should eventually be updated
to use to append and prepend symbols.

This includes a scripted mass convert of the config files to use
the new generic cmdline. There is a bit of a trim effect here.
It would seems that some of the config haven't been trimmed in
a while.

The script used is as follows,

if [[ -z "$1" || -z "$2" ]]; then
echo "Two arguments are needed."
exit 1
fi
mkdir $1
cp $2 $1/.config
sed -i 's/CONFIG_CMDLINE=/CONFIG_CMDLINE_BOOL=y\nCONFIG_CMDLINE_PREPEND=/g' 
$1/.config
make ARCH=$1 O=$1 olddefconfig
make ARCH=$1 O=$1 savedefconfig
cp $1/defconfig $2
rm -Rf $1

Cc: xe-linux-exter...@cisco.com
Signed-off-by: Ruslan Ruslichenko 
Signed-off-by: Ruslan Bilovol 
Signed-off-by: Daniel Walker 
---
 arch/mips/Kconfig |  4 +--
 arch/mips/Kconfig.debug   | 44 ---
 arch/mips/configs/ar7_defconfig   |  9 ++---
 arch/mips/configs/bcm47xx_defconfig   |  8 ++---
 arch/mips/configs/bcm63xx_defconfig   | 15 +++-
 arch/mips/configs/bmips_be_defconfig  | 11 +++---
 arch/mips/configs/bmips_stb_defconfig | 11 +++---
 arch/mips/configs/capcella_defconfig  | 11 ++
 arch/mips/configs/ci20_defconfig  | 10 +++---
 arch/mips/configs/cu1000-neo_defconfig| 10 +++---
 arch/mips/configs/cu1830-neo_defconfig| 10 +++---
 arch/mips/configs/e55_defconfig   |  4 +--
 arch/mips/configs/generic_defconfig   |  6 ++--
 arch/mips/configs/gpr_defconfig   | 18 ++
 arch/mips/configs/loongson3_defconfig | 13 ++-
 arch/mips/configs/mpc30x_defconfig|  7 ++--
 arch/mips/configs/tb0219_defconfig|  7 ++--
 arch/mips/configs/tb0226_defconfig|  7 ++--
 arch/mips/configs/tb0287_defconfig|  7 ++--
 arch/mips/configs/workpad_defconfig   | 11 +++---
 arch/mips/include/asm/setup.h |  2 ++
 arch/mips/kernel/relocate.c   | 17 +++--
 arch/mips/kernel/setup.c  | 36 +++
 arch/mips/pic32/pic32mzda/early_console.c |  2 +-
 arch/mips/pic32/pic32mzda/init.c  |  3 +-
 25 files changed, 78 insertions(+), 205 deletions(-)

diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index d89efba3d8a4..0e753894d28d 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -24,6 +24,7 @@ config MIPS
select CPU_NO_EFFICIENT_FFS if (TARGET_ISA_REV < 1)
select CPU_PM if CPU_IDLE
select GENERIC_ATOMIC64 if !64BIT
+   select GENERIC_CMDLINE
select GENERIC_CMOS_UPDATE
select GENERIC_CPU_AUTOPROBE
select GENERIC_GETTIMEOFDAY
@@ -3212,9 +3213,6 @@ choice
config MIPS_CMDLINE_FROM_BOOTLOADER
bool "Bootloader kernel arguments if available"
 
-   config MIPS_CMDLINE_BUILTIN_EXTEND
-   depends on CMDLINE_BOOL
-   bool "Extend builtin kernel arguments with bootloader arguments"
 endchoice
 
 endmenu
diff --git a/arch/mips/Kconfig.debug b/arch/mips/Kconfig.debug
index 7a8d94cdd493..b5a099c74eb6 100644
--- a/arch/mips/Kconfig.debug
+++ b/arch/mips/Kconfig.debug
@@ -30,50 +30,6 @@ config EARLY_PRINTK_8250
 config USE_GENERIC_EARLY_PRINTK_8250
bool
 
-config CMDLINE_BOOL
-   bool "Built-in kernel command line"
-   help
- For most systems, it is firmware or second stage bootloader that
- by default specifies the kernel command line options.  However,
- it might be necessary or advantageous to either override the
- default kernel command line or add a few extra options to it.
- For such cases, this option allows you to hardcode your own
- command line options directly into the kernel.  For that, you
- should choose 'Y' here, and fill in the extra boot arguments
- in CONFIG_CMDLINE.
-
- The built-in options will be concatenated to the default command
- line if CMDLINE_OVERRIDE is set to 'N'. Otherwise, the default
- command line will be ignored and replaced by the built-in string.
-
- Most MIPS systems will normally expect 'N' here and rely upon
- the command line from the firmware or the second-stage bootloader.
-
-config CMDLINE
-   string "Default kernel command string"
-   depends on CMDLINE_BOOL
-   help
- On some platforms, there is currently no way for the boot loader to
- pass arguments to the kernel.  For these platforms, and for the cases
- when you want to add some extra options to the command line or ignore
- the default comma

[PATCH 1/8] CMDLINE: add generic builtin command line

2021-04-15 Thread Daniel Walker
This code allows architectures to use a generic builtin command line.
The state of the builtin command line options across architecture is
diverse. MIPS and X86 once has similar systems, then mips added some
options to allow extending the command line. Powerpc did something
simiar in adding the ability to extend. Even with mips and powerpc
enhancement the needs of Cisco are not met on these platforms.

The code in this commit unifies the code into a generic
header file under the CONFIG_GENERIC_CMDLINE option. When this
option is enabled the architecture can call the cmdline_add_builtin()
to add the builtin command line. The generic code provides both
append and/or prepend options and provides a way to redefine these
option after the kernel is compiled.

This code also includes test's which are meant to confirm
functionality.

This unified implementation offers the same functionality needed by
Cisco on all platform which we enable it on.

Cc: xe-linux-exter...@cisco.com
Signed-off-by: Ruslan Bilovol 
Signed-off-by: Daniel Walker 
---
 include/linux/cmdline.h | 103 +
 init/Kconfig|  78 ++
 lib/Kconfig |   4 ++
 lib/Makefile|   3 +
 lib/generic_cmdline.S   |  53 +++
 lib/test_cmdline1.c | 139 
 6 files changed, 380 insertions(+)
 create mode 100644 include/linux/cmdline.h
 create mode 100644 lib/generic_cmdline.S
 create mode 100644 lib/test_cmdline1.c

diff --git a/include/linux/cmdline.h b/include/linux/cmdline.h
new file mode 100644
index ..34d9d8d14672
--- /dev/null
+++ b/include/linux/cmdline.h
@@ -0,0 +1,103 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_CMDLINE_H
+#define _LINUX_CMDLINE_H
+/*
+ *
+ * Copyright (C) 2006,2021. Cisco Systems, Inc.
+ *
+ * Generic Append/Prepend cmdline support.
+ */
+
+
+#include 
+#include 
+
+#ifdef CONFIG_CMDLINE_BOOL
+extern char cmdline_prepend[];
+extern char cmdline_append[];
+extern char cmdline_tmp[];
+#define CMDLINE_PREPEND cmdline_prepend
+#define CMDLINE_APPEND cmdline_append
+#define CMDLINE_TMP cmdline_tmp
+#define CMDLINE_STATIC_PREPEND CONFIG_CMDLINE_PREPEND
+#define CMDLINE_STATIC_APPEND CONFIG_CMDLINE_APPEND
+#else
+#define CMDLINE_PREPEND ""
+#define CMDLINE_APPEND ""
+#define CMDLINE_TMP ""
+#define CMDLINE_STATIC_PREPEND ""
+#define CMDLINE_STATIC_APPEND ""
+#endif
+
+#ifndef CMDLINE_STRLCAT
+#define CMDLINE_STRLCAT strlcat
+#endif
+
+#ifndef CMDLINE_STRLEN
+#define CMDLINE_STRLEN strlen
+#endif
+
+/*
+ * This function will append or prepend a builtin command line to the command
+ * line provided by the bootloader. Kconfig options can be used to alter
+ * the behavior of this builtin command line.
+ * @dest: The destination of the final appended/prepended string
+ * @tmp: temporary space used for prepending
+ * @prepend: string to prepend to @dest
+ * @append: string to append to @dest
+ * @length: the maximum length of the strings above.
+ * @cmdline_strlen: point to a compatible strlen
+ * @cmdline_strlcat: point to a compatible strlcat
+ * This function returns true when the builtin command line was copied 
successfully
+ * and false when there was not enough room to copy all parts of the command 
line.
+ */
+static inline bool
+__cmdline_add_builtin(
+   char *dest,
+   char *tmp,
+   char *prepend,
+   char *append,
+   unsigned long length,
+   size_t (*cmdline_strlen)(const char *s),
+   size_t (*cmdline_strlcat)(char *dest, const char *src, size_t 
count))
+{
+   size_t total_length = 0, tmp_length;
+
+   if (!IS_ENABLED(CONFIG_GENERIC_CMDLINE))
+   return true;
+
+   if (!IS_ENABLED(CONFIG_CMDLINE_BOOL))
+   return true;
+
+   if (IS_ENABLED(CONFIG_CMDLINE_OVERRIDE))
+   dest[0] = '\0';
+   else
+   total_length += cmdline_strlen(dest);
+
+   tmp_length = cmdline_strlen(append);
+   if (tmp_length > 0) {
+   cmdline_strlcat(dest, append, length);
+   total_length += tmp_length;
+   }
+
+   tmp_length = cmdline_strlen(prepend);
+   if (tmp_length > 0) {
+   cmdline_strlcat(tmp, prepend, length);
+   cmdline_strlcat(tmp, dest, length);
+   dest[0] = '\0';
+   cmdline_strlcat(dest, tmp, length);
+   total_length += tmp_length;
+   }
+
+   tmp[0] = '\0';
+
+   if (total_length > length)
+   return false;
+
+   return true;
+}
+
+#define cmdline_add_builtin(dest) \
+   __cmdline_add_builtin(dest, CMDLINE_TMP, CMDLINE_PREPEND, 
CMDLINE_APPEND, COMMAND_LINE_SIZE, CMDLINE_STRLEN, CMDLINE_STRLCAT)
+
+#endif
diff --git a/init/Kconfig b/init/Kconfig
index 5f5c776ef192..d72eb5a804c6 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -2034,6 +2034,84 @@ 

[PATCH 3/8] scripts: insert-sys-cert: change name to insert-symbol

2021-04-15 Thread Daniel Walker
Since the tool is used to update the command line and/or
to update the certificates, I think it makes sense to
changes the name of this tool.

Update the name of the tool to better reflect it's new use.

Cc: xe-linux-exter...@cisco.com
Signed-off-by: Daniel Walker 
---
 scripts/Makefile   | 2 +-
 scripts/{insert-sys-cert.c => insert-symbol.c} | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
 rename scripts/{insert-sys-cert.c => insert-symbol.c} (99%)

diff --git a/scripts/Makefile b/scripts/Makefile
index c36106bce80e..ed6b9f8f91fa 100644
--- a/scripts/Makefile
+++ b/scripts/Makefile
@@ -13,7 +13,7 @@ hostprogs-always-$(CONFIG_BUILDTIME_TABLE_SORT)   
+= sorttable
 hostprogs-always-$(CONFIG_ASN1)+= asn1_compiler
 hostprogs-always-$(CONFIG_MODULE_SIG_FORMAT)   += sign-file
 hostprogs-always-$(CONFIG_SYSTEM_TRUSTED_KEYRING)  += extract-cert
-hostprogs-always-$(CONFIG_SYSTEM_EXTRA_CERTIFICATE)+= insert-sys-cert
+hostprogs-always-$(CONFIG_SYSTEM_EXTRA_CERTIFICATE)+= insert-symbol
 
 HOSTCFLAGS_sorttable.o = -I$(srctree)/tools/include
 HOSTCFLAGS_asn1_compiler.o = -I$(srctree)/include
diff --git a/scripts/insert-sys-cert.c b/scripts/insert-symbol.c
similarity index 99%
rename from scripts/insert-sys-cert.c
rename to scripts/insert-symbol.c
index 77d3306cfbfb..6866e3a84974 100644
--- a/scripts/insert-sys-cert.c
+++ b/scripts/insert-symbol.c
@@ -7,7 +7,7 @@
  * This software may be used and distributed according to the terms
  * of the GNU General Public License, incorporated herein by reference.
  *
- * Usage: insert-sys-cert [-s  -b  -c 
+ * Usage: insert-symbol [-s  -b  -c 
  */
 
 #define _GNU_SOURCE
-- 
2.25.1



[PATCH 2/8] scripts: insert-sys-cert: add command line insert capability

2021-04-15 Thread Daniel Walker
This adds changes to the insert-sys-cert tool to allow updating
the cmdline_prepend and cmdline_append symbols in addition to
adding certificates.

Updating the cmdline symbols was tested on a PVH virtual machine
with a vmlinux, and with a bzImage which was repackaged on x86.

This commit intentionally keeps the tool filename the same to allow
the changes to be seen more easily. The next commit will change
the name of the tool.

Cc: xe-linux-exter...@cisco.com
Signed-off-by: Daniel Walker 
---
 scripts/insert-sys-cert.c | 241 +++---
 1 file changed, 170 insertions(+), 71 deletions(-)

diff --git a/scripts/insert-sys-cert.c b/scripts/insert-sys-cert.c
index 8902836c2342..77d3306cfbfb 100644
--- a/scripts/insert-sys-cert.c
+++ b/scripts/insert-sys-cert.c
@@ -30,6 +30,9 @@
 #define USED_SYM  "system_extra_cert_used"
 #define LSIZE_SYM "system_certificate_list_size"
 
+#define CMDLINE_APPEND "cmdline_append"
+#define CMDLINE_PREPEND "cmdline_prepend"
+
 #define info(format, args...) fprintf(stderr, "INFO:" format, ## args)
 #define warn(format, args...) fprintf(stdout, "WARNING: " format, ## args)
 #define  err(format, args...) fprintf(stderr, "ERROR:   " format, ## args)
@@ -267,95 +270,46 @@ static void print_sym(Elf_Ehdr *hdr, struct sym *s)
 
 static void print_usage(char *e)
 {
-   printf("Usage %s [-s ] -b  -c \n", e);
+   printf("Usage %s [-s ] -b  [ -c  | -p 
 | -a  ]-\n", e);
 }
 
-int main(int argc, char **argv)
+static char *cmdline_prepend, *cmdline_append;
+static char *system_map_file;
+static char *cert_file;
+static char *cli_name;
+
+static int insert_certificate(Elf_Ehdr *hdr)
 {
-   char *system_map_file = NULL;
-   char *vmlinux_file = NULL;
-   char *cert_file = NULL;
-   int vmlinux_size;
+   struct sym cert_sym, lsize_sym, used_sym;
+   Elf_Shdr *symtab = NULL;
+   unsigned long *lsize;
+   FILE *system_map;
int cert_size;
-   Elf_Ehdr *hdr;
char *cert;
-   FILE *system_map;
-   unsigned long *lsize;
int *used;
-   int opt;
-   Elf_Shdr *symtab = NULL;
-   struct sym cert_sym, lsize_sym, used_sym;
-
-   while ((opt = getopt(argc, argv, "b:c:s:")) != -1) {
-   switch (opt) {
-   case 's':
-   system_map_file = optarg;
-   break;
-   case 'b':
-   vmlinux_file = optarg;
-   break;
-   case 'c':
-   cert_file = optarg;
-   break;
-   default:
-   break;
-   }
-   }
 
-   if (!vmlinux_file || !cert_file) {
-   print_usage(argv[0]);
-   exit(EXIT_FAILURE);
+   if (!cert_file) {
+   print_usage(cli_name);
+   return EXIT_FAILURE;
}
 
cert = read_file(cert_file, _size);
if (!cert)
-   exit(EXIT_FAILURE);
-
-   hdr = map_file(vmlinux_file, _size);
-   if (!hdr)
-   exit(EXIT_FAILURE);
-
-   if (vmlinux_size < sizeof(*hdr)) {
-   err("Invalid ELF file.\n");
-   exit(EXIT_FAILURE);
-   }
-
-   if ((hdr->e_ident[EI_MAG0] != ELFMAG0) ||
-   (hdr->e_ident[EI_MAG1] != ELFMAG1) ||
-   (hdr->e_ident[EI_MAG2] != ELFMAG2) ||
-   (hdr->e_ident[EI_MAG3] != ELFMAG3)) {
-   err("Invalid ELF magic.\n");
-   exit(EXIT_FAILURE);
-   }
-
-   if (hdr->e_ident[EI_CLASS] != CURRENT_ELFCLASS) {
-   err("ELF class mismatch.\n");
-   exit(EXIT_FAILURE);
-   }
-
-   if (hdr->e_ident[EI_DATA] != endianness()) {
-   err("ELF endian mismatch.\n");
-   exit(EXIT_FAILURE);
-   }
-
-   if (hdr->e_shoff > vmlinux_size) {
-   err("Could not find section header.\n");
-   exit(EXIT_FAILURE);
-   }
+   return EXIT_FAILURE;
 
symtab = get_symbol_table(hdr);
if (!symtab) {
warn("Could not find the symbol table.\n");
if (!system_map_file) {
err("Please provide a System.map file.\n");
-   print_usage(argv[0]);
-   exit(EXIT_FAILURE);
+   print_usage(cli_name);
+   return EXIT_FAILURE;
}
 
system_map = fopen(system_map_file, "r");
if (!system_map) {
perror(system_map_file);
-   exit(EXIT_FAILURE);
+   return EXIT_FAILURE;
}
get_symbol_from_map(hdr, system_map, CERT_SYM, _sym);
ge

[PATCH 0/8] generic command line v4

2021-04-15 Thread Daniel Walker


v4 release changes

* Updated insert-sys-cert tool to change command line symbols after
  compilation.

This tool is used to release binary kernels internally to companies
and then later insert certificates for each product by consumers of
the binary kernel. Cisco uses this tool for this purpose.

Cisco has a similar need for the command line to be modified on a
binary released kernels similar to how certificates are setup.

* Added global symbols to hold append and prepend values.

These changes follow the system certificate code to allow the
insert-sys-cert tool to be used.

* Added a test case to confirm functionality.

Seemed sensible to add this to make sure everything is working.

* Dropped powerpc changes

Christophe Leroy has reservations about the features for powerpc. I
don't think his reservations are founded, and these changes should
fully work on powerpc. However, I dropped these changes so Christophe
can have more time to get comfortable with the changes.


Enjoy!


Daniel Walker (8):
  CMDLINE: add generic builtin command line
  scripts: insert-sys-cert: add command line insert capability
  scripts: insert-sys-cert: change name to insert-symbol
  CMDLINE: mips: convert to generic builtin command line
  drivers: firmware: efi: libstub: enable generic commandline
  CMDLINE: x86: convert to generic builtin command line
  of: allow sending a NULL value to early_init_dt_scan_chosen
  CMDLINE: arm64: convert to generic builtin command line

 arch/arm64/Kconfig|  33 +--
 arch/arm64/include/asm/setup.h|   2 +
 arch/arm64/kernel/idreg-override.c|   9 +-
 arch/mips/Kconfig |   4 +-
 arch/mips/Kconfig.debug   |  44 
 arch/mips/configs/ar7_defconfig   |   9 +-
 arch/mips/configs/bcm47xx_defconfig   |   8 +-
 arch/mips/configs/bcm63xx_defconfig   |  15 +-
 arch/mips/configs/bmips_be_defconfig  |  11 +-
 arch/mips/configs/bmips_stb_defconfig |  11 +-
 arch/mips/configs/capcella_defconfig  |  11 +-
 arch/mips/configs/ci20_defconfig  |  10 +-
 arch/mips/configs/cu1000-neo_defconfig|  10 +-
 arch/mips/configs/cu1830-neo_defconfig|  10 +-
 arch/mips/configs/e55_defconfig   |   4 +-
 arch/mips/configs/generic_defconfig   |   6 +-
 arch/mips/configs/gpr_defconfig   |  18 +-
 arch/mips/configs/loongson3_defconfig |  13 +-
 arch/mips/configs/mpc30x_defconfig|   7 +-
 arch/mips/configs/tb0219_defconfig|   7 +-
 arch/mips/configs/tb0226_defconfig|   7 +-
 arch/mips/configs/tb0287_defconfig|   7 +-
 arch/mips/configs/workpad_defconfig   |  11 +-
 arch/mips/include/asm/setup.h |   2 +
 arch/mips/kernel/relocate.c   |  17 +-
 arch/mips/kernel/setup.c  |  36 +--
 arch/mips/pic32/pic32mzda/early_console.c |   2 +-
 arch/mips/pic32/pic32mzda/init.c  |   3 +-
 arch/x86/Kconfig  |  44 +---
 arch/x86/kernel/setup.c   |  18 +-
 .../firmware/efi/libstub/efi-stub-helper.c|  29 +++
 drivers/firmware/efi/libstub/efi-stub.c   |   9 +
 drivers/firmware/efi/libstub/efistub.h|   1 +
 drivers/firmware/efi/libstub/x86-stub.c   |  13 +-
 drivers/of/fdt.c  |  44 ++--
 include/linux/cmdline.h   | 103 
 init/Kconfig  |  78 ++
 lib/Kconfig   |   4 +
 lib/Makefile  |   3 +
 lib/generic_cmdline.S |  53 
 lib/test_cmdline1.c   | 139 ++
 scripts/Makefile  |   2 +-
 .../{insert-sys-cert.c => insert-symbol.c}| 243 --
 43 files changed, 716 insertions(+), 394 deletions(-)
 create mode 100644 include/linux/cmdline.h
 create mode 100644 lib/generic_cmdline.S
 create mode 100644 lib/test_cmdline1.c
 rename scripts/{insert-sys-cert.c => insert-symbol.c} (72%)

-- 
2.25.1



Re: [PATCH 2/8] CMDLINE: drivers: of: ifdef out cmdline section

2021-04-08 Thread Daniel Walker
On Wed, Apr 07, 2021 at 05:59:15PM -0500, Rob Herring wrote:
> On Tue, Mar 30, 2021 at 04:17:53PM -0700, Daniel Walker wrote:
> > On Tue, Mar 30, 2021 at 02:49:13PM -0500, Rob Herring wrote:
> > > On Tue, Mar 30, 2021 at 12:57 PM Daniel Walker  wrote:
> > > >
> > > > It looks like there's some seepage of cmdline stuff into
> > > > the generic device tree code. This conflicts with the
> > > > generic cmdline implementation so I remove it in the case
> > > > when that's enabled.
> > > >
> > > > Cc: xe-linux-exter...@cisco.com
> > > > Signed-off-by: Ruslan Ruslichenko 
> > > > Signed-off-by: Daniel Walker 
> > > > ---
> > > >  drivers/of/fdt.c | 14 ++
> > > >  1 file changed, 14 insertions(+)
> > > >
> > > > diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
> > > > index dcc1dd96911a..d8805cd9717a 100644
> > > > --- a/drivers/of/fdt.c
> > > > +++ b/drivers/of/fdt.c
> > > > @@ -25,6 +25,7 @@
> > > >  #include 
> > > >  #include 
> > > >  #include 
> > > > +#include 
> > > >
> > > >  #include   /* for COMMAND_LINE_SIZE */
> > > >  #include 
> > > > @@ -1050,6 +1051,18 @@ int __init early_init_dt_scan_chosen(unsigned 
> > > > long node, const char *uname,
> > > >
> > > > /* Retrieve command line */
> > > > p = of_get_flat_dt_prop(node, "bootargs", );
> > > > +
> > > > +#if defined(CONFIG_GENERIC_CMDLINE) && 
> > > > defined(CONFIG_GENERIC_CMDLINE_OF)
> > > 
> > > Moving in the wrong direction... This code already has too many
> > > #ifdef's. I like Christophe's version as it gets rid of all the code
> > > here.
> >  
> > It's temporary .. Notice CONFIG_GENERIC_CMDLINE_OF is only used on PowerPC. 
> > I
> > experienced doubling on arm64 when this was used (i.e. the append and 
> > prepend
> > was added twice).
> > 
> > I don't think there are any other users which can't be moved outside the 
> > device
> > tree code, but powerpc uses this function three times during boot up plus 
> > the
> > prom_init user. It's possible to use the generic command line in all four 
> > places,
> > but it become space inefficient.
> 
> What's the 3rd use? I count kaslr code and in 
> early_init_dt_scan_chosen_ppc. Do we need to build the command line for 
> kaslr seed? Getting any build time value from the kernel is pointless.

I think I may have been mistaken. I added a dump_stack() , but there may have
been other stack traces during bootup on prior -rcX's I was testing.

I re-ran the test and I only see one user on powerpc and powerpc64,

powerpc64,

[T0] Call Trace:
[T0] [c1517d00] [c077e910] dump_stack+0xc4/0x114 
(unreliable)
[T0] [c1517d50] [c1186fb4] 
early_init_dt_scan_chosen+0x238/0x324
[T0] [c1517de0] [c1138b00] 
early_init_dt_scan_chosen_ppc+0x20/0x194
[T0] [c1517e10] [c1186ae0] of_scan_flat_dt+0xc8/0x130
[T0] [c1517e70] [c1139404] early_init_devtree+0xa4/0x48c
[T0] [c1517f10] [c113ac90] early_setup+0xc8/0x254
[T0] [c1517f90] [c754] 0xc754

powerpc32,

Call Trace:
[c06bbee0] [c067e334] early_init_dt_scan_chosen+0xf8/0x1dc (unreliable)
[c06bbf10] [c0666ec4] early_init_dt_scan_chosen_ppc+0x18/0x6c
[c06bbf30] [c067e048] of_scan_flat_dt+0x98/0xf4
[c06bbf70] [c0667234] early_init_devtree+0x48/0x2d0
[c06bbfb0] [c06679cc] machine_init+0x98/0xcc
[c06bbff0] [c398] set_ivor+0x114/0x154

I think it would be possible to just move the generic handling entire into
architecture code.

Daniel


Re: [PATCH v4 19/20] mips: Convert to GENERIC_CMDLINE

2021-04-08 Thread Daniel Walker
On Thu, Apr 08, 2021 at 02:04:08PM -0500, Rob Herring wrote:
> On Tue, Apr 06, 2021 at 10:38:36AM -0700, Daniel Walker wrote:
> > On Fri, Apr 02, 2021 at 03:18:21PM +, Christophe Leroy wrote:
> > > -config CMDLINE_BOOL
> > > - bool "Built-in kernel command line"
> > > - help
> > > -   For most systems, it is firmware or second stage bootloader that
> > > -   by default specifies the kernel command line options.  However,
> > > -   it might be necessary or advantageous to either override the
> > > -   default kernel command line or add a few extra options to it.
> > > -   For such cases, this option allows you to hardcode your own
> > > -   command line options directly into the kernel.  For that, you
> > > -   should choose 'Y' here, and fill in the extra boot arguments
> > > -   in CONFIG_CMDLINE.
> > > -
> > > -   The built-in options will be concatenated to the default command
> > > -   line if CMDLINE_OVERRIDE is set to 'N'. Otherwise, the default
> > > -   command line will be ignored and replaced by the built-in string.
> > > -
> > > -   Most MIPS systems will normally expect 'N' here and rely upon
> > > -   the command line from the firmware or the second-stage bootloader.
> > > -
> > 
> > 
> > See how you complained that I have CMDLINE_BOOL in my changed, and you 
> > think it
> > shouldn't exist.
> > 
> > Yet here mips has it, and you just deleted it with no feature parity in your
> > changes for this.
> 
> AFAICT, CMDLINE_BOOL equates to a non-empty or empty CONFIG_CMDLINE. You 
> seem to need it just because you have CMDLINE_PREPEND and 
> CMDLINE_APPEND. If that's not it, what feature is missing? CMDLINE_BOOL 
> is not a feature, but an implementation detail.

Not true.

It makes it easier to turn it all off inside the Kconfig , so it's for usability
and multiple architecture have it even with just CMDLINE as I was commenting
here.

Daniel


Re: [PATCH v4 19/20] mips: Convert to GENERIC_CMDLINE

2021-04-06 Thread Daniel Walker
On Fri, Apr 02, 2021 at 03:18:21PM +, Christophe Leroy wrote:
> -config CMDLINE_BOOL
> - bool "Built-in kernel command line"
> - help
> -   For most systems, it is firmware or second stage bootloader that
> -   by default specifies the kernel command line options.  However,
> -   it might be necessary or advantageous to either override the
> -   default kernel command line or add a few extra options to it.
> -   For such cases, this option allows you to hardcode your own
> -   command line options directly into the kernel.  For that, you
> -   should choose 'Y' here, and fill in the extra boot arguments
> -   in CONFIG_CMDLINE.
> -
> -   The built-in options will be concatenated to the default command
> -   line if CMDLINE_OVERRIDE is set to 'N'. Otherwise, the default
> -   command line will be ignored and replaced by the built-in string.
> -
> -   Most MIPS systems will normally expect 'N' here and rely upon
> -   the command line from the firmware or the second-stage bootloader.
> -


See how you complained that I have CMDLINE_BOOL in my changed, and you think it
shouldn't exist.

Yet here mips has it, and you just deleted it with no feature parity in your
changes for this.

In my changes I tried to maintain as much feature parity as I could with the
architectures. I did the same huge conversion a long time ago you've done here 
to be sure all
platforms have the features needed.

Daniel


Re: [PATCH v4 00/20] Implement GENERIC_CMDLINE

2021-04-06 Thread Daniel Walker
On Fri, Apr 02, 2021 at 03:18:01PM +, Christophe Leroy wrote:
> The purpose of this series is to improve and enhance the
> handling of kernel boot arguments.
> 
> Current situation is that most if not all architectures are using
> similar options to do some manupulation on command line arguments:
> - Prepend built-in arguments in front of bootloader provided arguments
> - Append built-in arguments after bootloader provided arguments
> - Replace bootloader provided arguments by built-in arguments
> - Use built-in arguments when none is provided by bootloader.
> 
> On some architectures, all the options are possible. On other ones,
> only a subset are available.
> 
> The purpose of this series is to refactor and enhance the
> handling of kernel boot arguments so that every architecture can
> benefit from all possibilities.
> 
> It is first focussed on powerpc but also extends the capability
> for other arches.
> 
> The work has been focussed on minimising the churn in architectures
> by keeping the most commonly used namings.
> 
> Main changes in V4:
> - Included patch from Daniel to replace powerpc's strcpy() by strlcpy()
> - Using strlcpy() instead of zeroing first char + strlcat() (idea taken frm 
> Daniel's series)
> - Reworked the convertion of EFI which was wrong in V3
> - Added "too long" command line handling
> - Changed cmdline macro into a function
> - Done a few fixes in arch (NIOS2, SH, ARM)
> - Taken comments into account (see individual responses for details)
> - Tested on powerpc, build tested on ARM64, X86_64.
> 

Why submit your changes ? My changes have been around for almost 10 years, and
are more widely used. Your changes are very new and unstable, but don't really
solve the needs of people using my series.

I've tried to work with you and I take comments from you, but yet you insist to
submit your own series.

I would suggest this isn't going to go anyplace unless we work together.

I can't really support your changes because, honestly, your changes are really
ugly and they just look more and more like my changes with every passing
iteration .. As the maturity of your changes continue they will just become my
change set.

I've been thru every iteration of these changes, and I see those attempts in
your changes. Everything different in your changes I've tried, and found not to
be useful, then it falls away in later iterations.

When you give me comments on something which I haven't tried I typically
incorporate it.

Daniel


Re: [PATCH 6/8] drivers: firmware: efi: libstub: enable generic commandline

2021-04-06 Thread Daniel Walker
On Fri, Apr 02, 2021 at 07:36:53PM +0200, Christophe Leroy wrote:
> 
> 
> Le 30/03/2021 à 19:57, Daniel Walker a écrit :
> > This adds code to handle the generic command line changes.
> > The efi code appears that it doesn't benefit as much from this design
> > as it could.
> > 
> > For example, if you had a prepend command line with "nokaslr" then
> > you might be helpful to re-enable it in the boot loader or dts,
> > but there appears to be no way to re-enable kaslr or some of the
> > other options.
> > 
> > Cc: xe-linux-exter...@cisco.com
> > Signed-off-by: Daniel Walker 
> > ---
> >   .../firmware/efi/libstub/efi-stub-helper.c| 35 +++
> >   drivers/firmware/efi/libstub/efi-stub.c   |  7 
> >   drivers/firmware/efi/libstub/efistub.h|  1 +
> >   drivers/firmware/efi/libstub/x86-stub.c   | 13 +--
> >   4 files changed, 54 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/firmware/efi/libstub/efi-stub-helper.c 
> > b/drivers/firmware/efi/libstub/efi-stub-helper.c
> > index aa8da0a49829..c155837cedc9 100644
> > --- a/drivers/firmware/efi/libstub/efi-stub-helper.c
> > +++ b/drivers/firmware/efi/libstub/efi-stub-helper.c
> > @@ -13,6 +13,7 @@
> >   #include 
> >   #include 
> >   #include  /* For CONSOLE_LOGLEVEL_* */
> > +#include 
> >   #include 
> >   #include 
> > @@ -172,6 +173,40 @@ int efi_printk(const char *fmt, ...)
> > return printed;
> >   }
> > +/**
> > + * efi_handle_cmdline() - handle adding in building parts of the command 
> > line
> > + * @cmdline:   kernel command line
> > + *
> > + * Add in the generic parts of the commandline and start the parsing of the
> > + * command line.
> > + *
> > + * Return: status code
> > + */
> > +efi_status_t efi_handle_cmdline(char const *cmdline)
> > +{
> > +   efi_status_t status;
> > +
> > +   status = efi_parse_options(CMDLINE_PREPEND);
> > +   if (status != EFI_SUCCESS) {
> > +   efi_err("Failed to parse options\n");
> > +   return status;
> > +   }
> > +
> > +   status = efi_parse_options(IS_ENABLED(CONFIG_CMDLINE_OVERRIDE) ? "" : 
> > cmdline);
> > +   if (status != EFI_SUCCESS) {
> > +   efi_err("Failed to parse options\n");
> > +   return status;
> > +   }
> > +
> > +   status = efi_parse_options(CMDLINE_APPEND);
> > +   if (status != EFI_SUCCESS) {
> > +   efi_err("Failed to parse options\n");
> > +   return status;
> > +   }
> > +
> > +   return EFI_SUCCESS;
> > +}
> 
> I think we can refactor to first build the final command line, then call
> efi_parse_options() only once after that.
 
I tried this, like what you did in your v4 .. The issues are similar to the
prom_init.c problems. The environment is delicate and requires careful
programming to get it done correctly.

> The big advantage of GENERIC_CMDLINE should be to not address anymore
> CONFIG_CMDLINE_XXX options at all outside of linux/cmdline.h
 
I agree , but not I've found that it's not likely to get this all changed in a
single series.

Daniel


Re: [PATCH 4/8] CMDLINE: powerpc: convert to generic builtin command line

2021-04-06 Thread Daniel Walker
On Fri, Apr 02, 2021 at 07:34:19PM +0200, Christophe Leroy wrote:
> 
> 
> Le 30/03/2021 à 19:56, Daniel Walker a écrit :
> > This updates the powerpc code to use the CONFIG_GENERIC_CMDLINE
> > option.
> > 
> > This includes a scripted mass convert of the config files to use
> > the new generic cmdline. There is a bit of a trim effect here.
> > It would seems that some of the config haven't been trimmed in
> > a while.
> 
> Sorry, this patch is not acceptable as is, the default for powerpc is
> CMDLINE_FROM_BOOTLOADER, ie builtin-cmdline is taken if and only if none is
> provided by the bootloader.
> 
> As far as I understand, that disappear with this patch.

We've talked about it previously. Maybe your not understanding the precedent of
the command line options. I tried to explain that one before.

What problems do you think are caused if this patch is applied ?

Daniel


Re: [PATCH 2/8] CMDLINE: drivers: of: ifdef out cmdline section

2021-04-06 Thread Daniel Walker
On Fri, Apr 02, 2021 at 07:32:08PM +0200, Christophe Leroy wrote:
> 
> 
> Le 30/03/2021 à 19:56, Daniel Walker a écrit :
> > It looks like there's some seepage of cmdline stuff into
> > the generic device tree code. This conflicts with the
> > generic cmdline implementation so I remove it in the case
> > when that's enabled.
> > 
> > Cc: xe-linux-exter...@cisco.com
> > Signed-off-by: Ruslan Ruslichenko 
> > Signed-off-by: Daniel Walker 
> > ---
> >   drivers/of/fdt.c | 14 ++
> >   1 file changed, 14 insertions(+)
> > 
> > diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
> > index dcc1dd96911a..d8805cd9717a 100644
> > --- a/drivers/of/fdt.c
> > +++ b/drivers/of/fdt.c
> > @@ -25,6 +25,7 @@
> >   #include 
> >   #include 
> >   #include 
> > +#include 
> >   #include   /* for COMMAND_LINE_SIZE */
> >   #include 
> > @@ -1050,6 +1051,18 @@ int __init early_init_dt_scan_chosen(unsigned long 
> > node, const char *uname,
> > /* Retrieve command line */
> > p = of_get_flat_dt_prop(node, "bootargs", );
> > +
> > +#if defined(CONFIG_GENERIC_CMDLINE) && defined(CONFIG_GENERIC_CMDLINE_OF)
> > +   /*
> > +* The builtin command line will be added here, or it can override
> > +* with the DT bootargs.
> > +*/
> > +   cmdline_add_builtin(data,
> > +   (l > 0 ? p : NULL), /* This is sanity checking */
> > +   COMMAND_LINE_SIZE);
> > +#elif defined(CONFIG_GENERIC_CMDLINE)
> > +   strlcpy(data, p, COMMAND_LINE_SIZE);
> > +#else
> 
> Ugly.
> 
> Linux codying style recommend to limit the use of #ifdefs to headers as much 
> as possible.
> 
> Why do we need so many alternatives ? Allthough they are temporary, can we
> order the changes in another way to reduce that ?

I think this whole section can be removed down even all the CMDLINE ifdef's ..
The only architecture which needs this is powerpc because it calls this function
three times.

If powerpc were made to call this only once , and then call the generic handling
for the command line then this whole section would get removed.

Daniel


Re: [PATCH v2 3/7] powerpc: convert config files to generic cmdline

2021-04-06 Thread Daniel Walker
On Thu, Apr 01, 2021 at 03:08:04PM -0500, Rob Herring wrote:
> On Tue, Mar 30, 2021 at 6:31 PM Daniel Walker  wrote:
> >
> > On Tue, Mar 30, 2021 at 03:13:04PM -0500, Rob Herring wrote:
> > > On Tue, Mar 30, 2021 at 12:33 PM Daniel Walker  wrote:
> > > >
> > > > On Thu, Mar 25, 2021 at 05:29:44PM -0600, Rob Herring wrote:
> > > > > On Thu, Mar 25, 2021 at 2:00 PM Daniel Walker  
> > > > > wrote:
> > > > > >
> > > > > > On Thu, Mar 25, 2021 at 01:03:55PM +0100, Christophe Leroy wrote:
> > > > > > >
> > > > > > > Ok, so you agree we don't need to provide two CMDLINE, one to be 
> > > > > > > appended and one to be prepended.
> > > > > > >
> > > > > > > Let's only provide once CMDLINE as of today, and ask the user to 
> > > > > > > select
> > > > > > > whether he wants it appended or prepended or replacee. Then no 
> > > > > > > need to
> > > > > > > change all existing config to rename CONFIG_CMDLINE into either 
> > > > > > > of the new
> > > > > > > ones.
> > > > > > >
> > > > > > > That's the main difference between my series and Daniel's series. 
> > > > > > > So I'll
> > > > > > > finish taking Will's comment into account and we'll send out a v3 
> > > > > > > soon.
> > > > > >
> > > > > > It doesn't solve the needs of Cisco, I've stated many times your 
> > > > > > changes have
> > > > > > little value. Please stop submitting them.
> > > > >
> > > > > Can you please outline what those needs are which aren't met?
> > > >
> > > > append AND prepend at the same time on all architectures. Christophe 
> > > > doesn't
> > > > understand the need, and hence tries to minimize the feature set which 
> > > > is
> > > > incompatible with Cisco needs and all the other out of tree users.
> > >
> > > Okay, but that's never been a feature in upstream. For upstream, we
> > > refactor first and add features 2nd. In this case, the difference is
> > > largely the kconfig and it would be better to not change the options
> > > twice, but that's not a blocker for taking the refactoring. You won't
> > > find a maintainer that's going to take adding a feature over cleanups
> > > and unification.
> >
> > It kind of is a feature in upstream, it's a matter of opinion. Some platform
> > used append and some use prepend, and it's likely because the maintainers 
> > needed
> > one or the other for development.
> 
> Which arch/platform upstream does both prepend and append at the same time?
 
None do it at the same time, however x86 and mips have switched between the 
two. 

> > I'm not sure why you think I can't add the features in one go. It would be
> > horrid to take Christophe's changes, then have to do basically all the same 
> > work
> > a second time which is what Christophe's changes would force me to do.
> 
> I didn't say it couldn't be done. In fact, I said it would be better
> all at once: "it would be better to not change the options twice"
> 
> But both of you ignoring comments and continuing to post competing
> series is not going to get us there. TBC, I think Christophe's series
> is much closer to being in shape to merge upstream.
 
I'm not the one ignoring comments .. I've taken a number of comments from
Christophe, but he still submits his own series..

Christophe series doesn't look good to me.. I suspect you like it cause it
deletes lines from of.

> > Say for example I implement this change only on one architecture. In that 
> > case
> > the maintainer would be accepting a feature enhancement , but there would 
> > be no
> > stopping it. I shouldn't have to go two strokes on one architecture, but 
> > each
> > change I'm making is essentially a single architecture. They can go in all
> > together or one at a time.
> 
> Features do get implemented all the time on one arch. And then maybe a
> 2nd and 3rd. At some point we decide no more copying, it needs to be
> common and refactored. We're at that point for cmdline handling IMO.

I don't think it can be done with one series all at once ..

Daniel


Re: [PATCH 6/8] drivers: firmware: efi: libstub: enable generic commandline

2021-03-31 Thread Daniel Walker
On Wed, Mar 31, 2021 at 06:10:08PM +0200, Ard Biesheuvel wrote:
> (+ Arvind)
> 
> On Tue, 30 Mar 2021 at 19:57, Daniel Walker  wrote:
> >
> > This adds code to handle the generic command line changes.
> > The efi code appears that it doesn't benefit as much from this design
> > as it could.
> >
> > For example, if you had a prepend command line with "nokaslr" then
> > you might be helpful to re-enable it in the boot loader or dts,
> > but there appears to be no way to re-enable kaslr or some of the
> > other options.
> >
> > Cc: xe-linux-exter...@cisco.com
> > Signed-off-by: Daniel Walker 
> > ---
> >  .../firmware/efi/libstub/efi-stub-helper.c| 35 +++
> >  drivers/firmware/efi/libstub/efi-stub.c   |  7 
> >  drivers/firmware/efi/libstub/efistub.h|  1 +
> >  drivers/firmware/efi/libstub/x86-stub.c   | 13 +--
> >  4 files changed, 54 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/firmware/efi/libstub/efi-stub-helper.c 
> > b/drivers/firmware/efi/libstub/efi-stub-helper.c
> > index aa8da0a49829..c155837cedc9 100644
> > --- a/drivers/firmware/efi/libstub/efi-stub-helper.c
> > +++ b/drivers/firmware/efi/libstub/efi-stub-helper.c
> > @@ -13,6 +13,7 @@
> >  #include 
> >  #include 
> >  #include  /* For CONSOLE_LOGLEVEL_* */
> > +#include 
> >  #include 
> >  #include 
> >
> > @@ -172,6 +173,40 @@ int efi_printk(const char *fmt, ...)
> > return printed;
> >  }
> >
> > +/**
> > + * efi_handle_cmdline() - handle adding in building parts of the command 
> > line
> > + * @cmdline:   kernel command line
> > + *
> > + * Add in the generic parts of the commandline and start the parsing of the
> > + * command line.
> > + *
> > + * Return: status code
> > + */
> > +efi_status_t efi_handle_cmdline(char const *cmdline)
> > +{
> > +   efi_status_t status;
> > +
> > +   status = efi_parse_options(CMDLINE_PREPEND);
> > +   if (status != EFI_SUCCESS) {
> > +   efi_err("Failed to parse options\n");
> > +   return status;
> > +   }
> 
> Even though I am not a fan of the 'success handling' pattern,
> duplicating the exact same error handling three times is not great
> either. Could we reuse more of the code here?

How about

efi_status_t status = 0;

status |= efi_parse_options(CMDLINE_PREPEND);

then error checking once ?

> > +
> > +   status = efi_parse_options(IS_ENABLED(CONFIG_CMDLINE_OVERRIDE) ? "" 
> > : cmdline);
> 
> What is the point of calling efi_parse_options() with an empty string?
 
I could change it to if ((IS_ENABLED(CONFIG_CMDLINE_OVERRIDE)) ?

> > --- a/drivers/firmware/efi/libstub/efi-stub.c
> > +++ b/drivers/firmware/efi/libstub/efi-stub.c
> > @@ -172,6 +172,12 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
> > goto fail;
> > }
> >
> > +#ifdef CONFIG_GENERIC_CMDLINE
> > +   status = efi_handle_cmdline(cmdline_ptr);
> > +   if (status != EFI_SUCCESS) {
> > +   goto fail_free_cmdline;
> > +   }
> > +#else
> > if (IS_ENABLED(CONFIG_CMDLINE_EXTEND) ||
> > IS_ENABLED(CONFIG_CMDLINE_FORCE) ||
> 
> Does this mean CONFIG_GENERIC_CMDLINE does not replace CMDLINE_EXTEND
> / CMDLINE_FORCE etc, but introduces yet another variant on top of
> those?
> 
> That does not seem like an improvement to me. I think it is great that
> you are cleaning this up, but only if it means we can get rid of the
> old implementation.
 
It does replace extend and force. I was under the impression this code was
shared between arm64 and arm32. If that's not the case I can delete the extend
and force section. I haven't submitted a conversion for arm32 yet.

Daniel


Re: [PATCH] arm64: Add support for cisco craw64 ARMv8 SoCs

2021-03-31 Thread Daniel Walker
On Wed, Mar 31, 2021 at 09:04:15AM +0200, Arnd Bergmann wrote:
> On Wed, Mar 31, 2021 at 3:46 AM Daniel Walker  wrote:
> > From: Ofer Licht 
> 
> Thanks for the submission, it's always nice to see a new platform
 

> > Define craw64 config, dts and Makefile for Cisco
> > SoCs known as Craw.
> 
> I'd like some more information about the platform, e.g. the target
> market and maybe a link to the product information.

Our SoC is produced as an internal product. So SoC specifications aren't
widely available.

Here is an example of a Cisco product which uses this SoC,

https://www.cisco.com/c/en/us/products/collateral/switches/catalyst-9200-series-switches/nb-06-cat9200-ser-data-sheet-cte-en.html

I suspect that's not really what your looking for tho.

> > Cc: xe-linux-exter...@cisco.com
> > Signed-off-by: Ofer Licht 
> > Signed-off-by: Daniel Walker 
> > ---
> >  .../devicetree/bindings/vendor-prefixes.yaml  |   2 +
> >  arch/arm64/Kconfig.platforms  |   5 +
> >  arch/arm64/boot/dts/Makefile  |   1 +
> >  arch/arm64/boot/dts/cisco/Makefile|   5 +
> >  .../arm64/boot/dts/cisco/craw64-dopplerg2.dts | 239 +++
> >  arch/arm64/boot/dts/cisco/craw64.dtsi | 392 ++
> >  arch/arm64/configs/defconfig  |   1 +
> 
> We have separate branches for dt, defconfig, and the rest, so it would be
> good to split this patch up a little more.
> 
> There should also be an entry in the top-level MAINTAINERS file.
> 
> > diff --git a/arch/arm64/boot/dts/cisco/craw64-dopplerg2.dts 
> > b/arch/arm64/boot/dts/cisco/craw64-dopplerg2.dts
> > new file mode 100644
> > index ..20ecc57b4e5c
> > --- /dev/null
> > +++ b/arch/arm64/boot/dts/cisco/craw64-dopplerg2.dts
> > @@ -0,0 +1,239 @@
> > +/dts-v1/;
> > +
> > +#include "craw64.dtsi"
> > +
> > +/ {
> > +   model = "Cisco Craw64 on DopplerG 2.0";
> > +   compatible = "cisco,craw64-dopplerg2", "cisco,craw64";
> > +
> > +   memory {
> > +   device_type = "memory";
> > +   reg = <0x0 0x8000 0x0 0x8000>;
> > +   };
> 
> The memory size is usually filled by the boot loader, just put an
> empty node into the .dtsi file

Arnd, I must regretfully inform you that Cisco has a deep dark addiction to
bootloaders which, are, um, how do I say this diplomatically, um , brain dead.

You have some other comments below related to moving things into the bootloader,
and I can look into it, but bootloader inflexibility is wide spread inside
Cisco.

> 
> > +   doppler {
> > +   #address-cells = <2>;
> > +   #size-cells = <2>;
> > +   compatible = "simple-bus";
> > +   ranges;
> > +   };
> 
> What is this?
> 

It's a device, but the driver is not submitted. I can remove it along with the
other device driver binding we have where the drivers and bindings aren't 
submitted.

I'll do my best to fix the comments your given an resubmit.

Daniel


Re: [PATCH v2 3/7] powerpc: convert config files to generic cmdline

2021-03-31 Thread Daniel Walker
On Wed, Mar 31, 2021 at 12:52:19PM +0100, Will Deacon wrote:
> On Tue, Mar 30, 2021 at 10:35:21AM -0700, Daniel Walker wrote:
> > On Mon, Mar 29, 2021 at 11:07:51AM +0100, Will Deacon wrote:
> > > On Thu, Mar 25, 2021 at 12:59:56PM -0700, Daniel Walker wrote:
> > > > On Thu, Mar 25, 2021 at 01:03:55PM +0100, Christophe Leroy wrote:
> > > > > 
> > > > > Ok, so you agree we don't need to provide two CMDLINE, one to be 
> > > > > appended and one to be prepended.
> > > > > 
> > > > > Let's only provide once CMDLINE as of today, and ask the user to 
> > > > > select
> > > > > whether he wants it appended or prepended or replacee. Then no need to
> > > > > change all existing config to rename CONFIG_CMDLINE into either of 
> > > > > the new
> > > > > ones.
> > > > > 
> > > > > That's the main difference between my series and Daniel's series. So 
> > > > > I'll
> > > > > finish taking Will's comment into account and we'll send out a v3 
> > > > > soon.
> > > > 
> > > > It doesn't solve the needs of Cisco, I've stated many times your 
> > > > changes have
> > > > little value. Please stop submitting them.
> > > 
> > > FWIW, they're useful for arm64 and I will gladly review the updated 
> > > series.
> > > 
> > > I don't think asking people to stop submitting patches is ever the right
> > > answer. Please don't do that.
> > 
> > Why ? It's me nacking his series, is that not allowed anymore ?
> 
> If you're that way inclined then you can "nack" whatever you want, but
> please allow the rest of us to continue reviewing the patches. You don't
> have any basis on which to veto other people's contributions and so
> demanding that somebody stops posting code is neither constructive nor
> meaningful.

I understand , but that's not what's happening. I've dealt with Christophe on
these changes repeatedly, and he's demonstrated he doesn't understand the 
feature set or
the motivation of the changes. I've tried to work with him in the past, but it
doesn't work unless he's giving me comments on my changes.

His changes don't solve Cisco problems, and likely never will regardless of
feedback. Maybe that could change, but I don't see that happening.

Daniel


[PATCH] arm64: Add support for cisco craw64 ARMv8 SoCs

2021-03-30 Thread Daniel Walker
From: Ofer Licht 

Define craw64 config, dts and Makefile for Cisco
SoCs known as Craw.

Cc: xe-linux-exter...@cisco.com
Signed-off-by: Ofer Licht 
Signed-off-by: Daniel Walker 
---
 .../devicetree/bindings/vendor-prefixes.yaml  |   2 +
 arch/arm64/Kconfig.platforms  |   5 +
 arch/arm64/boot/dts/Makefile  |   1 +
 arch/arm64/boot/dts/cisco/Makefile|   5 +
 .../arm64/boot/dts/cisco/craw64-dopplerg2.dts | 239 +++
 arch/arm64/boot/dts/cisco/craw64.dtsi | 392 ++
 arch/arm64/configs/defconfig  |   1 +
 7 files changed, 645 insertions(+)
 create mode 100644 arch/arm64/boot/dts/cisco/Makefile
 create mode 100644 arch/arm64/boot/dts/cisco/craw64-dopplerg2.dts
 create mode 100644 arch/arm64/boot/dts/cisco/craw64.dtsi

diff --git a/Documentation/devicetree/bindings/vendor-prefixes.yaml 
b/Documentation/devicetree/bindings/vendor-prefixes.yaml
index f6064d84a424..10ac5fa4c3e7 100644
--- a/Documentation/devicetree/bindings/vendor-prefixes.yaml
+++ b/Documentation/devicetree/bindings/vendor-prefixes.yaml
@@ -229,6 +229,8 @@ patternProperties:
 description: Chuwi Innovation Ltd.
   "^ciaa,.*":
 description: Computadora Industrial Abierta Argentina
+  "^cisco,.*":
+description: Cisco Systems, Inc
   "^cirrus,.*":
 description: Cirrus Logic, Inc.
   "^cisco,.*":
diff --git a/arch/arm64/Kconfig.platforms b/arch/arm64/Kconfig.platforms
index cdfd5fed457f..861f16ceec9d 100644
--- a/arch/arm64/Kconfig.platforms
+++ b/arch/arm64/Kconfig.platforms
@@ -91,6 +91,11 @@ config ARCH_BRCMSTB
help
  This enables support for Broadcom's ARMv8 Set Top Box SoCs
 
+config ARCH_CRAW64
+   bool "Cisco craw64 ARMv8 SoC Family"
+   help
+ This enables support for Cisco craw64 ARMv8 SoCs
+
 config ARCH_EXYNOS
bool "ARMv8 based Samsung Exynos SoC family"
select COMMON_CLK_SAMSUNG
diff --git a/arch/arm64/boot/dts/Makefile b/arch/arm64/boot/dts/Makefile
index f1173cd93594..10fbd54f4424 100644
--- a/arch/arm64/boot/dts/Makefile
+++ b/arch/arm64/boot/dts/Makefile
@@ -10,6 +10,7 @@ subdir-y += arm
 subdir-y += bitmain
 subdir-y += broadcom
 subdir-y += cavium
+subdir-y += cisco
 subdir-y += exynos
 subdir-y += freescale
 subdir-y += hisilicon
diff --git a/arch/arm64/boot/dts/cisco/Makefile 
b/arch/arm64/boot/dts/cisco/Makefile
new file mode 100644
index ..8503887f6a7d
--- /dev/null
+++ b/arch/arm64/boot/dts/cisco/Makefile
@@ -0,0 +1,5 @@
+dtb-$(CONFIG_ARCH_CRAW64) += craw64-dopplerg2.dtb
+
+always  := $(dtb-y)
+subdir-y:= $(dts-dirs)
+clean-files := *.dtb
diff --git a/arch/arm64/boot/dts/cisco/craw64-dopplerg2.dts 
b/arch/arm64/boot/dts/cisco/craw64-dopplerg2.dts
new file mode 100644
index ..20ecc57b4e5c
--- /dev/null
+++ b/arch/arm64/boot/dts/cisco/craw64-dopplerg2.dts
@@ -0,0 +1,239 @@
+/dts-v1/;
+
+#include "craw64.dtsi"
+
+/ {
+   model = "Cisco Craw64 on DopplerG 2.0";
+   compatible = "cisco,craw64-dopplerg2", "cisco,craw64";
+
+   memory {
+   device_type = "memory";
+   reg = <0x0 0x8000 0x0 0x8000>;
+   };
+
+   soc: soc {
+   uart0: serial@23f8 {
+   clock-frequency = <25000>;
+   status = "ok";
+   };
+
+   uart1: serial@23fc {
+   clock-frequency = <25000>;
+   status = "ok";
+   };
+
+   spiclk: spiclk {
+   clock-frequency = <25000>;
+   };
+
+   spi: spi@2400 {
+   status="ok";
+   flash: flash@0 {
+   compatible = "micron,n25q128a13", 
"jedec,spi-nor";
+   #address-cells = <1>;
+   #size-cells = <1>;
+   spi-max-frequency = <800>;
+   reg = <0>;
+   partition@0 {
+   label = "unused0";
+   reg = <0x0 0x1>;
+   read-only;
+   };
+   partition@1 {
+   label = "brom";
+   reg = <0x1 0x1>;
+   };
+   partition@2 {
+   label = "bromg";
+   reg = <0x2 0x1>;
+   read-only;
+ 

Re: [PATCH v2 3/7] powerpc: convert config files to generic cmdline

2021-03-30 Thread Daniel Walker
On Tue, Mar 30, 2021 at 03:13:04PM -0500, Rob Herring wrote:
> On Tue, Mar 30, 2021 at 12:33 PM Daniel Walker  wrote:
> >
> > On Thu, Mar 25, 2021 at 05:29:44PM -0600, Rob Herring wrote:
> > > On Thu, Mar 25, 2021 at 2:00 PM Daniel Walker  wrote:
> > > >
> > > > On Thu, Mar 25, 2021 at 01:03:55PM +0100, Christophe Leroy wrote:
> > > > >
> > > > > Ok, so you agree we don't need to provide two CMDLINE, one to be 
> > > > > appended and one to be prepended.
> > > > >
> > > > > Let's only provide once CMDLINE as of today, and ask the user to 
> > > > > select
> > > > > whether he wants it appended or prepended or replacee. Then no need to
> > > > > change all existing config to rename CONFIG_CMDLINE into either of 
> > > > > the new
> > > > > ones.
> > > > >
> > > > > That's the main difference between my series and Daniel's series. So 
> > > > > I'll
> > > > > finish taking Will's comment into account and we'll send out a v3 
> > > > > soon.
> > > >
> > > > It doesn't solve the needs of Cisco, I've stated many times your 
> > > > changes have
> > > > little value. Please stop submitting them.
> > >
> > > Can you please outline what those needs are which aren't met?
> >
> > append AND prepend at the same time on all architectures. Christophe doesn't
> > understand the need, and hence tries to minimize the feature set which is
> > incompatible with Cisco needs and all the other out of tree users.
> 
> Okay, but that's never been a feature in upstream. For upstream, we
> refactor first and add features 2nd. In this case, the difference is
> largely the kconfig and it would be better to not change the options
> twice, but that's not a blocker for taking the refactoring. You won't
> find a maintainer that's going to take adding a feature over cleanups
> and unification.

It kind of is a feature in upstream, it's a matter of opinion. Some platform
used append and some use prepend, and it's likely because the maintainers needed
one or the other for development.

I'm not sure why you think I can't add the features in one go. It would be
horrid to take Christophe's changes, then have to do basically all the same work
a second time which is what Christophe's changes would force me to do.

Say for example I implement this change only on one architecture. In that case
the maintainer would be accepting a feature enhancement , but there would be no
stopping it. I shouldn't have to go two strokes on one architecture, but each
change I'm making is essentially a single architecture. They can go in all
together or one at a time.

Daniel


Re: [PATCH 2/8] CMDLINE: drivers: of: ifdef out cmdline section

2021-03-30 Thread Daniel Walker
On Tue, Mar 30, 2021 at 02:49:13PM -0500, Rob Herring wrote:
> On Tue, Mar 30, 2021 at 12:57 PM Daniel Walker  wrote:
> >
> > It looks like there's some seepage of cmdline stuff into
> > the generic device tree code. This conflicts with the
> > generic cmdline implementation so I remove it in the case
> > when that's enabled.
> >
> > Cc: xe-linux-exter...@cisco.com
> > Signed-off-by: Ruslan Ruslichenko 
> > Signed-off-by: Daniel Walker 
> > ---
> >  drivers/of/fdt.c | 14 ++
> >  1 file changed, 14 insertions(+)
> >
> > diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
> > index dcc1dd96911a..d8805cd9717a 100644
> > --- a/drivers/of/fdt.c
> > +++ b/drivers/of/fdt.c
> > @@ -25,6 +25,7 @@
> >  #include 
> >  #include 
> >  #include 
> > +#include 
> >
> >  #include   /* for COMMAND_LINE_SIZE */
> >  #include 
> > @@ -1050,6 +1051,18 @@ int __init early_init_dt_scan_chosen(unsigned long 
> > node, const char *uname,
> >
> > /* Retrieve command line */
> > p = of_get_flat_dt_prop(node, "bootargs", );
> > +
> > +#if defined(CONFIG_GENERIC_CMDLINE) && defined(CONFIG_GENERIC_CMDLINE_OF)
> 
> Moving in the wrong direction... This code already has too many
> #ifdef's. I like Christophe's version as it gets rid of all the code
> here.
 
It's temporary .. Notice CONFIG_GENERIC_CMDLINE_OF is only used on PowerPC. I
experienced doubling on arm64 when this was used (i.e. the append and prepend
was added twice).

I don't think there are any other users which can't be moved outside the device
tree code, but powerpc uses this function three times during boot up plus the
prom_init user. It's possible to use the generic command line in all four 
places,
but it become space inefficient.

So the plan would be make the other architectures call the generic cmdline
directly without this code, then powerpc would need to be reworked to call the
generic commandline in it's own code hopefully just once.

The end results would be this section would reduce down to one string copy and
no command line stuff.

Maybe you would rather I just use the generic command line in those three place
and reduce this at the space code of powerpc ?

Daniel


Re: [PATCH v3 01/17] cmdline: Add generic function to build command line.

2021-03-30 Thread Daniel Walker
On Tue, Mar 30, 2021 at 08:07:30PM +0200, H. Nikolaus Schaller wrote:
> 
> > Am 30.03.2021 um 19:27 schrieb Daniel Walker :
> > 
> > On Fri, Mar 26, 2021 at 01:44:48PM +, Christophe Leroy wrote:
> >> This code provides architectures with a way to build command line
> >> based on what is built in the kernel and what is handed over by the
> >> bootloader, based on selected compile-time options.
> >> 
> >> Signed-off-by: Christophe Leroy 
> >> ---
> >> v3:
> >> - Addressed comments from Will
> >> - Added capability to have src == dst
> >> ---
> >> include/linux/cmdline.h | 57 +
> >> 1 file changed, 57 insertions(+)
> >> create mode 100644 include/linux/cmdline.h
> >> 
> >> diff --git a/include/linux/cmdline.h b/include/linux/cmdline.h
> >> new file mode 100644
> >> index ..dea87edd41be
> >> --- /dev/null
> >> +++ b/include/linux/cmdline.h
> >> @@ -0,0 +1,57 @@
> >> +/* SPDX-License-Identifier: GPL-2.0 */
> >> +#ifndef _LINUX_CMDLINE_H
> >> +#define _LINUX_CMDLINE_H
> >> +
> >> +#include 
> >> +
> >> +/* Allow architectures to override strlcat, powerpc can't use strings so 
> >> early */
> >> +#ifndef cmdline_strlcat
> >> +#define cmdline_strlcat strlcat
> >> +#endif
> >> +
> >> +/*
> >> + * This function will append or prepend a builtin command line to the 
> >> command
> >> + * line provided by the bootloader. Kconfig options can be used to alter
> >> + * the behavior of this builtin command line.
> >> + * @dst: The destination of the final appended/prepended string.
> >> + * @src: The starting string or NULL if there isn't one.
> >> + * @len: the length of dest buffer.
> >> + */
> > 
> > Append or prepend ? Cisco requires both at the same time. This is why my
> > implementation provides both. I can't use this with both at once.
> 
> Just an idea: what about defining CMDLINE as a pattern where e.g. "$$" or "%%"
> is replaced by the boot loader command line?
> 
> Then you can formulate replace, prepend, append, prepend+append with a single
> CONFIG setting.
> 
> It may be a little more complex in code (scanning for the pattern and 
> replacing
> it and take care to temporary memory) but IMHO it could be worth to consider.

In some cases this code could be used extremely early in boot up. For example 
in the
prom_init.c powerpc code, or in efi changes. The flexibility to find and replace
like that is not always an option due to the nature of the environment. It's not
impossible of course.

Daniel


[PATCH 8/8] CMDLINE: arm64: convert to generic builtin command line

2021-03-30 Thread Daniel Walker
This updates the arm64 code to use the CONFIG_GENERIC_CMDLINE
option.

Cc: xe-linux-exter...@cisco.com
Signed-off-by: Daniel Walker 
---
 arch/arm64/Kconfig | 33 +-
 arch/arm64/kernel/idreg-override.c |  8 +---
 arch/arm64/kernel/setup.c  |  4 
 3 files changed, 10 insertions(+), 35 deletions(-)

diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index e4e1b6550115..9781ba3758b1 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -105,6 +105,7 @@ config ARM64
select GENERIC_ALLOCATOR
select GENERIC_ARCH_TOPOLOGY
select GENERIC_CLOCKEVENTS_BROADCAST
+   select GENERIC_CMDLINE
select GENERIC_CPU_AUTOPROBE
select GENERIC_CPU_VULNERABILITIES
select GENERIC_EARLY_IOREMAP
@@ -1841,38 +1842,6 @@ config ARM64_ACPI_PARKING_PROTOCOL
  protocol even if the corresponding data is present in the ACPI
  MADT table.
 
-config CMDLINE
-   string "Default kernel command string"
-   default ""
-   help
- Provide a set of default command-line options at build time by
- entering them here. As a minimum, you should specify the the
- root device (e.g. root=/dev/nfs).
-
-choice
-   prompt "Kernel command line type" if CMDLINE != ""
-   default CMDLINE_FROM_BOOTLOADER
-   help
- Choose how the kernel will handle the provided default kernel
- command line string.
-
-config CMDLINE_FROM_BOOTLOADER
-   bool "Use bootloader kernel arguments if available"
-   help
- Uses the command-line options passed by the boot loader. If
- the boot loader doesn't provide any, the default kernel command
- string provided in CMDLINE will be used.
-
-config CMDLINE_FORCE
-   bool "Always use the default kernel command string"
-   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.
-
-endchoice
-
 config EFI_STUB
bool
 
diff --git a/arch/arm64/kernel/idreg-override.c 
b/arch/arm64/kernel/idreg-override.c
index 83f1c4b92095..fb10cd860a26 100644
--- a/arch/arm64/kernel/idreg-override.c
+++ b/arch/arm64/kernel/idreg-override.c
@@ -9,6 +9,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -188,11 +189,12 @@ static __init void parse_cmdline(void)
 {
const u8 *prop = get_bootargs_cmdline();
 
-   if (IS_ENABLED(CONFIG_CMDLINE_FORCE) || !prop)
-   __parse_cmdline(CONFIG_CMDLINE, true);
+   __parse_cmdline(CMDLINE_PREPEND, true);
 
-   if (!IS_ENABLED(CONFIG_CMDLINE_FORCE) && prop)
+   if (IS_ENABLED(CMDLINE_OVERRIDE) && prop)
__parse_cmdline(prop, true);
+
+   __parse_cmdline(CMDLINE_APPEND, true);
 }
 
 /* Keep checkers quiet */
diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c
index 61845c0821d9..01791ce5244c 100644
--- a/arch/arm64/kernel/setup.c
+++ b/arch/arm64/kernel/setup.c
@@ -30,6 +30,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -322,6 +323,9 @@ void __init __no_sanitize_address setup_arch(char 
**cmdline_p)
 * cpufeature code and early parameters.
 */
jump_label_init();
+
+   cmdline_add_builtin(boot_command_line, NULL, COMMAND_LINE_SIZE);
+
parse_early_param();
 
/*
-- 
2.25.1



[PATCH 7/8] CMDLINE: x86: convert to generic builtin command line

2021-03-30 Thread Daniel Walker
This updates the x86 code to use the CONFIG_GENERIC_CMDLINE
option.

Cc: xe-linux-exter...@cisco.com
Signed-off-by: Ruslan Ruslichenko 
Signed-off-by: Ruslan Bilovol 
Signed-off-by: Daniel Walker 
---
 arch/x86/Kconfig| 44 +
 arch/x86/kernel/setup.c | 18 ++---
 2 files changed, 3 insertions(+), 59 deletions(-)

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 2792879d398e..73ea9589e50d 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -118,6 +118,7 @@ config X86
select EDAC_SUPPORT
select GENERIC_CLOCKEVENTS_BROADCASTif X86_64 || (X86_32 && 
X86_LOCAL_APIC)
select GENERIC_CLOCKEVENTS_MIN_ADJUST
+   select GENERIC_CMDLINE
select GENERIC_CMOS_UPDATE
select GENERIC_CPU_AUTOPROBE
select GENERIC_CPU_VULNERABILITIES
@@ -2358,49 +2359,6 @@ choice
 
 endchoice
 
-config CMDLINE_BOOL
-   bool "Built-in kernel command line"
-   help
- Allow for specifying boot arguments to the kernel at
- build time.  On some systems (e.g. embedded ones), it is
- necessary or convenient to provide some or all of the
- kernel boot arguments with the kernel itself (that is,
- to not rely on the boot loader to provide them.)
-
- To compile command line arguments into the kernel,
- set this option to 'Y', then fill in the
- boot arguments in CONFIG_CMDLINE.
-
- Systems with fully functional boot loaders (i.e. non-embedded)
- should leave this option set to 'N'.
-
-config CMDLINE
-   string "Built-in kernel command string"
-   depends on CMDLINE_BOOL
-   default ""
-   help
- Enter arguments here that should be compiled into the kernel
- image and used at boot time.  If the boot loader provides a
- command line at boot time, it is appended to this string to
- form the full kernel command line, when the system boots.
-
- However, you can use the CONFIG_CMDLINE_OVERRIDE option to
- change this behavior.
-
- In most cases, the command line (whether built-in or provided
- by the boot loader) should specify the device for the root
- file system.
-
-config CMDLINE_OVERRIDE
-   bool "Built-in command line overrides boot loader arguments"
-   depends on CMDLINE_BOOL && CMDLINE != ""
-   help
- Set this option to 'Y' to have the kernel ignore the boot loader
- command line, and use ONLY the built-in command line.
-
- This is used to work around broken boot loaders.  This should
- be set to 'N' under normal conditions.
-
 config MODIFY_LDT_SYSCALL
bool "Enable the LDT (local descriptor table)" if EXPERT
default y
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index d883176ef2ce..6444a5f1fabf 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -47,6 +47,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /*
  * max_low_pfn_mapped: highest directly mapped pfn < 4 GB
@@ -161,9 +162,6 @@ unsigned long saved_video_mode;
 #define RAMDISK_LOAD_FLAG  0x4000
 
 static char __initdata command_line[COMMAND_LINE_SIZE];
-#ifdef CONFIG_CMDLINE_BOOL
-static char __initdata builtin_cmdline[COMMAND_LINE_SIZE] = CONFIG_CMDLINE;
-#endif
 
 #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
 struct edd edd;
@@ -883,19 +881,7 @@ void __init setup_arch(char **cmdline_p)
bss_resource.start = __pa_symbol(__bss_start);
bss_resource.end = __pa_symbol(__bss_stop)-1;
 
-#ifdef CONFIG_CMDLINE_BOOL
-#ifdef CONFIG_CMDLINE_OVERRIDE
-   strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
-#else
-   if (builtin_cmdline[0]) {
-   /* append boot loader cmdline to builtin */
-   strlcat(builtin_cmdline, " ", COMMAND_LINE_SIZE);
-   strlcat(builtin_cmdline, boot_command_line, COMMAND_LINE_SIZE);
-   strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
-   }
-#endif
-#endif
-
+   cmdline_add_builtin(boot_command_line, NULL, COMMAND_LINE_SIZE);
strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
*cmdline_p = command_line;
 
-- 
2.25.1



[PATCH 6/8] drivers: firmware: efi: libstub: enable generic commandline

2021-03-30 Thread Daniel Walker
This adds code to handle the generic command line changes.
The efi code appears that it doesn't benefit as much from this design
as it could.

For example, if you had a prepend command line with "nokaslr" then
you might be helpful to re-enable it in the boot loader or dts,
but there appears to be no way to re-enable kaslr or some of the
other options.

Cc: xe-linux-exter...@cisco.com
Signed-off-by: Daniel Walker 
---
 .../firmware/efi/libstub/efi-stub-helper.c| 35 +++
 drivers/firmware/efi/libstub/efi-stub.c   |  7 
 drivers/firmware/efi/libstub/efistub.h|  1 +
 drivers/firmware/efi/libstub/x86-stub.c   | 13 +--
 4 files changed, 54 insertions(+), 2 deletions(-)

diff --git a/drivers/firmware/efi/libstub/efi-stub-helper.c 
b/drivers/firmware/efi/libstub/efi-stub-helper.c
index aa8da0a49829..c155837cedc9 100644
--- a/drivers/firmware/efi/libstub/efi-stub-helper.c
+++ b/drivers/firmware/efi/libstub/efi-stub-helper.c
@@ -13,6 +13,7 @@
 #include 
 #include 
 #include  /* For CONSOLE_LOGLEVEL_* */
+#include 
 #include 
 #include 
 
@@ -172,6 +173,40 @@ int efi_printk(const char *fmt, ...)
return printed;
 }
 
+/**
+ * efi_handle_cmdline() - handle adding in building parts of the command line
+ * @cmdline:   kernel command line
+ *
+ * Add in the generic parts of the commandline and start the parsing of the
+ * command line.
+ *
+ * Return: status code
+ */
+efi_status_t efi_handle_cmdline(char const *cmdline)
+{
+   efi_status_t status;
+
+   status = efi_parse_options(CMDLINE_PREPEND);
+   if (status != EFI_SUCCESS) {
+   efi_err("Failed to parse options\n");
+   return status;
+   }
+
+   status = efi_parse_options(IS_ENABLED(CONFIG_CMDLINE_OVERRIDE) ? "" : 
cmdline);
+   if (status != EFI_SUCCESS) {
+   efi_err("Failed to parse options\n");
+   return status;
+   }
+
+   status = efi_parse_options(CMDLINE_APPEND);
+   if (status != EFI_SUCCESS) {
+   efi_err("Failed to parse options\n");
+   return status;
+   }
+
+   return EFI_SUCCESS;
+}
+
 /**
  * efi_parse_options() - Parse EFI command line options
  * @cmdline:   kernel command line
diff --git a/drivers/firmware/efi/libstub/efi-stub.c 
b/drivers/firmware/efi/libstub/efi-stub.c
index 26e69788f27a..760480248adf 100644
--- a/drivers/firmware/efi/libstub/efi-stub.c
+++ b/drivers/firmware/efi/libstub/efi-stub.c
@@ -172,6 +172,12 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
goto fail;
}
 
+#ifdef CONFIG_GENERIC_CMDLINE
+   status = efi_handle_cmdline(cmdline_ptr);
+   if (status != EFI_SUCCESS) {
+   goto fail_free_cmdline;
+   }
+#else
if (IS_ENABLED(CONFIG_CMDLINE_EXTEND) ||
IS_ENABLED(CONFIG_CMDLINE_FORCE) ||
cmdline_size == 0) {
@@ -189,6 +195,7 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
goto fail_free_cmdline;
}
}
+#endif
 
efi_info("Booting Linux Kernel...\n");
 
diff --git a/drivers/firmware/efi/libstub/efistub.h 
b/drivers/firmware/efi/libstub/efistub.h
index cde0a2ef507d..07c7f9fdfffc 100644
--- a/drivers/firmware/efi/libstub/efistub.h
+++ b/drivers/firmware/efi/libstub/efistub.h
@@ -800,6 +800,7 @@ efi_status_t efi_relocate_kernel(unsigned long *image_addr,
 unsigned long alignment,
 unsigned long min_addr);
 
+efi_status_t efi_handle_cmdline(char const *cmdline);
 efi_status_t efi_parse_options(char const *cmdline);
 
 void efi_parse_option_graphics(char *option);
diff --git a/drivers/firmware/efi/libstub/x86-stub.c 
b/drivers/firmware/efi/libstub/x86-stub.c
index f14c4ff5839f..30ad8fb7122d 100644
--- a/drivers/firmware/efi/libstub/x86-stub.c
+++ b/drivers/firmware/efi/libstub/x86-stub.c
@@ -673,6 +673,8 @@ unsigned long efi_main(efi_handle_t handle,
unsigned long bzimage_addr = (unsigned long)startup_32;
unsigned long buffer_start, buffer_end;
struct setup_header *hdr = _params->hdr;
+   unsigned long cmdline_paddr = ((u64)hdr->cmd_line_ptr |
+  ((u64)boot_params->ext_cmd_line_ptr << 
32));
efi_status_t status;
 
efi_system_table = sys_table_arg;
@@ -735,6 +737,14 @@ unsigned long efi_main(efi_handle_t handle,
image_offset = 0;
}
 
+#ifdef CONFIG_GENERIC_CMDLINE
+   status = efi_handle_cmdline((char *)cmdline_paddr);
+   if (status != EFI_SUCCESS) {
+   efi_err("Failed to parse options\n");
+   goto fail;
+   }
+#else /* CONFIG_GENERIC_CMDLINE */
+
 #ifdef CONFIG_CMDLINE_BOOL
status = efi_parse_options(CONFIG_CMDLINE);
if (status != EFI_SUCCESS) {
@@ -743,8 +753,6 @@ unsigned long efi_main(e

[PATCH 5/8] CMDLINE: mips: convert to generic builtin command line

2021-03-30 Thread Daniel Walker
This updates the mips code to use the CONFIG_GENERIC_CMDLINE
option.

This deletes the option for MIPS_CMDLINE_BUILTIN_EXTEND
and replaces the functionality with generic code.

This includes a scripted mass convert of the config files to use
the new generic cmdline. There is a bit of a trim effect here.
It would seems that some of the config haven't been trimmed in
a while.

The script used is as follows,

if [[ -z "$1" || -z "$2" ]]; then
echo "Two arguments are needed."
exit 1
fi
mkdir $1
cp $2 $1/.config
sed -i 's/CONFIG_CMDLINE=/CONFIG_CMDLINE_BOOL=y\nCONFIG_CMDLINE_PREPEND=/g' 
$1/.config
make ARCH=$1 O=$1 olddefconfig
make ARCH=$1 O=$1 savedefconfig
cp $1/defconfig $2
rm -Rf $1

Cc: xe-linux-exter...@cisco.com
Signed-off-by: Ruslan Ruslichenko 
Signed-off-by: Ruslan Bilovol 
Signed-off-by: Daniel Walker 
---
 arch/mips/Kconfig  |  4 +--
 arch/mips/Kconfig.debug| 44 --
 arch/mips/configs/ar7_defconfig|  9 ++
 arch/mips/configs/bcm47xx_defconfig|  8 ++---
 arch/mips/configs/bcm63xx_defconfig| 15 +++--
 arch/mips/configs/bmips_be_defconfig   | 11 +++
 arch/mips/configs/bmips_stb_defconfig  | 11 +++
 arch/mips/configs/capcella_defconfig   | 11 ++-
 arch/mips/configs/ci20_defconfig   | 10 +++---
 arch/mips/configs/cu1000-neo_defconfig | 10 +++---
 arch/mips/configs/cu1830-neo_defconfig | 10 +++---
 arch/mips/configs/e55_defconfig|  4 +--
 arch/mips/configs/generic_defconfig|  6 ++--
 arch/mips/configs/gpr_defconfig| 18 ++-
 arch/mips/configs/loongson3_defconfig  | 13 ++--
 arch/mips/configs/mpc30x_defconfig |  7 ++--
 arch/mips/configs/tb0219_defconfig |  7 ++--
 arch/mips/configs/tb0226_defconfig |  7 ++--
 arch/mips/configs/tb0287_defconfig |  7 ++--
 arch/mips/configs/workpad_defconfig| 11 +++
 arch/mips/kernel/setup.c   | 36 +++--
 21 files changed, 59 insertions(+), 200 deletions(-)

diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index d89efba3d8a4..0e753894d28d 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -24,6 +24,7 @@ config MIPS
select CPU_NO_EFFICIENT_FFS if (TARGET_ISA_REV < 1)
select CPU_PM if CPU_IDLE
select GENERIC_ATOMIC64 if !64BIT
+   select GENERIC_CMDLINE
select GENERIC_CMOS_UPDATE
select GENERIC_CPU_AUTOPROBE
select GENERIC_GETTIMEOFDAY
@@ -3212,9 +3213,6 @@ choice
config MIPS_CMDLINE_FROM_BOOTLOADER
bool "Bootloader kernel arguments if available"
 
-   config MIPS_CMDLINE_BUILTIN_EXTEND
-   depends on CMDLINE_BOOL
-   bool "Extend builtin kernel arguments with bootloader arguments"
 endchoice
 
 endmenu
diff --git a/arch/mips/Kconfig.debug b/arch/mips/Kconfig.debug
index 7a8d94cdd493..b5a099c74eb6 100644
--- a/arch/mips/Kconfig.debug
+++ b/arch/mips/Kconfig.debug
@@ -30,50 +30,6 @@ config EARLY_PRINTK_8250
 config USE_GENERIC_EARLY_PRINTK_8250
bool
 
-config CMDLINE_BOOL
-   bool "Built-in kernel command line"
-   help
- For most systems, it is firmware or second stage bootloader that
- by default specifies the kernel command line options.  However,
- it might be necessary or advantageous to either override the
- default kernel command line or add a few extra options to it.
- For such cases, this option allows you to hardcode your own
- command line options directly into the kernel.  For that, you
- should choose 'Y' here, and fill in the extra boot arguments
- in CONFIG_CMDLINE.
-
- The built-in options will be concatenated to the default command
- line if CMDLINE_OVERRIDE is set to 'N'. Otherwise, the default
- command line will be ignored and replaced by the built-in string.
-
- Most MIPS systems will normally expect 'N' here and rely upon
- the command line from the firmware or the second-stage bootloader.
-
-config CMDLINE
-   string "Default kernel command string"
-   depends on CMDLINE_BOOL
-   help
- On some platforms, there is currently no way for the boot loader to
- pass arguments to the kernel.  For these platforms, and for the cases
- when you want to add some extra options to the command line or ignore
- the default command line, you can supply some command-line options at
- build time by entering them here.  In other cases you can specify
- kernel args so that you don't have to set them up in board prom
- initialization routines.
-
- For more information, see the CMDLINE_BOOL and CMDLINE_OVERRIDE
- options.
-
-config CMDLINE_OVERRIDE
-   bool "Built-in command line overrides firmware arguments"
-   depends on CMDLINE_BOOL
-   help
- By setting this o

[PATCH 4/8] CMDLINE: powerpc: convert to generic builtin command line

2021-03-30 Thread Daniel Walker
This updates the powerpc code to use the CONFIG_GENERIC_CMDLINE
option.

This includes a scripted mass convert of the config files to use
the new generic cmdline. There is a bit of a trim effect here.
It would seems that some of the config haven't been trimmed in
a while.

The bash script used to convert is as follows,

if [[ -z "$1" || -z "$2" ]]; then
echo "Two arguments are needed."
exit 1
fi
mkdir $1
cp $2 $1/.config
sed -i 's/CONFIG_CMDLINE=/CONFIG_CMDLINE_BOOL=y\nCONFIG_CMDLINE_PREPEND=/g' 
$1/.config
make ARCH=$1 O=$1 olddefconfig
make ARCH=$1 O=$1 savedefconfig
cp $1/defconfig $2
rm -Rf $1

Cc: xe-linux-exter...@cisco.com
Signed-off-by: Ruslan Ruslichenko 
Signed-off-by: Ruslan Bilovol 
Signed-off-by: Daniel Walker 
---
 arch/powerpc/Kconfig  | 38 +--
 arch/powerpc/configs/44x/fsp2_defconfig   | 32 
 arch/powerpc/configs/44x/iss476-smp_defconfig | 24 ++--
 arch/powerpc/configs/44x/warp_defconfig   | 17 -
 arch/powerpc/configs/holly_defconfig  | 13 ---
 arch/powerpc/configs/mvme5100_defconfig   | 23 +--
 arch/powerpc/configs/skiroot_defconfig| 12 +++---
 arch/powerpc/configs/storcenter_defconfig | 18 -
 arch/powerpc/kernel/prom_init.c   | 10 +++--
 9 files changed, 74 insertions(+), 113 deletions(-)

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 386ae12d8523..3a19e5b74177 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -167,6 +167,8 @@ config PPC
select EDAC_SUPPORT
select GENERIC_ATOMIC64 if PPC32
select GENERIC_CLOCKEVENTS_BROADCASTif SMP
+   select GENERIC_CMDLINE
+   select GENERIC_CMDLINE_OF
select GENERIC_CMOS_UPDATE
select GENERIC_CPU_AUTOPROBE
select GENERIC_CPU_VULNERABILITIES  if PPC_BARRIER_NOSPEC
@@ -886,42 +888,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
-   string "Initial kernel command string"
-   default ""
-   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.
-
-choice
-   prompt "Kernel command line type" if CMDLINE != ""
-   default CMDLINE_FROM_BOOTLOADER
-
-config CMDLINE_FROM_BOOTLOADER
-   bool "Use bootloader kernel arguments if available"
-   help
- Uses the command-line options passed by the boot loader. If
- the boot loader doesn't provide any, the default kernel command
- string provided in CMDLINE will be used.
-
-config CMDLINE_EXTEND
-   bool "Extend bootloader kernel arguments"
-   help
- The command-line arguments provided by the boot loader will be
- appended to the default kernel command string.
-
-config CMDLINE_FORCE
-   bool "Always use the default kernel command string"
-   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.
-
-endchoice
-
 config EXTRA_TARGETS
string "Additional default image types"
help
diff --git a/arch/powerpc/configs/44x/fsp2_defconfig 
b/arch/powerpc/configs/44x/fsp2_defconfig
index 8da316e61a08..4993db054589 100644
--- a/arch/powerpc/configs/44x/fsp2_defconfig
+++ b/arch/powerpc/configs/44x/fsp2_defconfig
@@ -1,8 +1,6 @@
-CONFIG_44x=y
 # CONFIG_SWAP is not set
 CONFIG_SYSVIPC=y
 # CONFIG_CROSS_MEMORY_ATTACH is not set
-# CONFIG_FHANDLE is not set
 CONFIG_NO_HZ=y
 CONFIG_HIGH_RES_TIMERS=y
 CONFIG_IKCONFIG=y
@@ -13,23 +11,25 @@ CONFIG_BLK_DEV_INITRD=y
 # CONFIG_RD_XZ is not set
 # CONFIG_RD_LZO is not set
 # CONFIG_RD_LZ4 is not set
+# CONFIG_FHANDLE is not set
 CONFIG_KALLSYMS_ALL=y
 CONFIG_BPF_SYSCALL=y
 CONFIG_EMBEDDED=y
 CONFIG_PROFILING=y
-CONFIG_MODULES=y
-CONFIG_MODULE_UNLOAD=y
-# CONFIG_BLK_DEV_BSG is not set
+CONFIG_CMDLINE_BOOL=y
+CONFIG_CMDLINE_PREPEND="ip=on rw"
+CONFIG_44x=y
 CONFIG_PPC_47x=y
 # CONFIG_EBONY is not set
 CONFIG_FSP2=y
 CONFIG_476FPE_ERR46=y
-CONFIG_SWIOTLB=y
 CONFIG_KEXEC=y
 CONFIG_CRASH_DUMP=y
-CONFIG_CMDLINE="ip=on rw"
 # CONFIG_SUSPEND is not set
-# CONFIG_PCI is not set
+CONFIG_OPROFILE=y
+CONFIG_MODULES=y
+CONFIG_MODULE_UNLOAD=y
+# CONFIG_BLK_DEV_BSG is not set
 CONFIG_NET=y
 CONFIG_PACKET=y
 CONFIG_UNIX=y
@@ -46,14 +46,12 @@ CONFIG_MTD=y
 CONFIG_MTD_BLOCK=y
 CONFIG_MTD_JEDECPROBE=y
 CONFIG_MTD_CFI_AMDSTD=y
-C

[PATCH 3/8] powerpc: convert strcpy to strlcpy in prom_init

2021-03-30 Thread Daniel Walker
There's only two users of strcpy and one is the command
line handling. The generic command line handling uses strlcpy
and it makes sense to convert this one other user to strlcpy to
keep prom_init size consistent.

Cc: xe-linux-exter...@cisco.com
Signed-off-by: Daniel Walker 
---
 arch/powerpc/kernel/prom_init.c | 25 +++--
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/arch/powerpc/kernel/prom_init.c b/arch/powerpc/kernel/prom_init.c
index ccf77b985c8f..2c2f33155317 100644
--- a/arch/powerpc/kernel/prom_init.c
+++ b/arch/powerpc/kernel/prom_init.c
@@ -242,15 +242,6 @@ static int __init prom_strcmp(const char *cs, const char 
*ct)
return 0;
 }
 
-static char __init *prom_strcpy(char *dest, const char *src)
-{
-   char *tmp = dest;
-
-   while ((*dest++ = *src++) != '\0')
-   /* nothing */;
-   return tmp;
-}
-
 static int __init prom_strncmp(const char *cs, const char *ct, size_t count)
 {
unsigned char c1, c2;
@@ -276,6 +267,20 @@ static size_t __init prom_strlen(const char *s)
return sc - s;
 }
 
+static size_t __init prom_strlcpy(char *dest, const char *src, size_t size)
+{
+   size_t ret = prom_strlen(src);
+
+   if (size) {
+   size_t len = (ret >= size) ? size - 1 : ret;
+
+   memcpy(dest, src, len);
+   dest[len] = '\0';
+   }
+   return ret;
+}
+
+
 static int __init prom_memcmp(const void *cs, const void *ct, size_t count)
 {
const unsigned char *su1, *su2;
@@ -2702,7 +2707,7 @@ static void __init flatten_device_tree(void)
 
/* Add "phandle" in there, we'll need it */
namep = make_room(_start, _end, 16, 1);
-   prom_strcpy(namep, "phandle");
+   prom_strlcpy(namep, "phandle", 8);
mem_start = (unsigned long)namep + prom_strlen(namep) + 1;
 
/* Build string array */
-- 
2.25.1



[PATCH 1/8] CMDLINE: add generic builtin command line

2021-03-30 Thread Daniel Walker
This code allows architectures to use a generic builtin command line.
The state of the builtin command line options across architecture is
diverse. MIPS and X86 once has similar systems, then mips added some
options to allow extending the command line. Powerpc did something
simiar in adding the ability to extend. Even with mips and powerpc
enhancement the needs of Cisco are not met on these platforms.

The code in this commit unifies the code into a generic
header file under the CONFIG_GENERIC_CMDLINE option. When this
option is enabled the architecture can call the cmdline_add_builtin()
to add the builtin command line.

This unified implementation offers the same functionality needed by
Cisco on all platform which use it.

Cc: xe-linux-exter...@cisco.com
Signed-off-by: Ruslan Bilovol 
Signed-off-by: Daniel Walker 
---
 include/linux/cmdline.h | 98 +
 init/Kconfig| 72 ++
 2 files changed, 170 insertions(+)
 create mode 100644 include/linux/cmdline.h

diff --git a/include/linux/cmdline.h b/include/linux/cmdline.h
new file mode 100644
index ..439c4585feba
--- /dev/null
+++ b/include/linux/cmdline.h
@@ -0,0 +1,98 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_CMDLINE_H
+#define _LINUX_CMDLINE_H
+
+/*
+ *
+ * Copyright (C) 2006,2021. Cisco Systems, Inc.
+ *
+ * Generic Append/Prepend cmdline support.
+ */
+
+#if defined(CONFIG_GENERIC_CMDLINE) && defined(CONFIG_CMDLINE_BOOL)
+
+#ifndef CONFIG_CMDLINE_OVERRIDE
+#define GENERIC_CMDLINE_NEED_STRLCAT
+#define CMDLINE_PREPEND CONFIG_CMDLINE_PREPEND
+#define CMDLINE_APPEND CONFIG_CMDLINE_APPEND
+
+/*
+ * This function will append or prepend a builtin command line to the command
+ * line provided by the bootloader. Kconfig options can be used to alter
+ * the behavior of this builtin command line.
+ * @dest: The destination of the final appended/prepended string
+ * @src: The starting string or NULL if there isn't one.
+ * @tmp: temporary space used for prepending
+ * @length: the maximum length of the strings above.
+ * @cmdline_strlcpy: point to a compatible strlcpy
+ * @cmdline_strlcat: point to a compatible strlcat
+ */
+static inline void
+__cmdline_add_builtin(char *dest, const char *src, char *tmp, unsigned long 
length,
+   size_t (*cmdline_strlcpy)(char *dest, const char *src, size_t 
size),
+   size_t (*cmdline_strlcat)(char *dest, const char *src, size_t 
count))
+{
+   if (src != dest && src != NULL) {
+   cmdline_strlcpy(dest, " ", length);
+   cmdline_strlcat(dest, src, length);
+   }
+
+   if (sizeof(CONFIG_CMDLINE_APPEND) > 1)
+   cmdline_strlcat(dest, " " CONFIG_CMDLINE_APPEND, length);
+
+   if (sizeof(CONFIG_CMDLINE_PREPEND) > 1) {
+   cmdline_strlcpy(tmp, CONFIG_CMDLINE_PREPEND " ", length);
+   cmdline_strlcat(tmp, dest, length);
+   cmdline_strlcpy(dest, tmp, length);
+   }
+}
+
+#define cmdline_add_builtin_custom(dest, src, length, label, cmdline_strlcpy, 
cmdline_strlcat) \
+{  
\
+   if (sizeof(CONFIG_CMDLINE_PREPEND) > 1) {   
\
+   static label char cmdline_tmp_space[length];
\
+   __cmdline_add_builtin(dest, src, cmdline_tmp_space, length, 
cmdline_strlcpy, cmdline_strlcat);  \
+   } else if (sizeof(CONFIG_CMDLINE_APPEND) > 1) { 
\
+   __cmdline_add_builtin(dest, src, NULL, length, cmdline_strlcpy, 
cmdline_strlcat);   \
+   }   
\
+}
+#define cmdline_add_builtin(dest, src, length) \
+   cmdline_add_builtin_custom(dest, src, length, __initdata, strlcpy, 
strlcat)
+
+#else /* CONFIG_CMDLINE_OVERRIDE */
+
+#define CMDLINE_PREPEND CONFIG_CMDLINE_PREPEND
+#define CMDLINE_APPEND CONFIG_CMDLINE_APPEND
+
+static inline void
+__cmdline_add_builtin_custom(char *dest, const char *src, unsigned long length,
+   size_t (*cmdline_strlcpy)(char *dest, const char *src, size_t 
size))
+{
+   cmdline_strlcpy(dest, CONFIG_CMDLINE_PREPEND " " CONFIG_CMDLINE_APPEND, 
length);
+}
+#define cmdline_add_builtin_custom(dest, src, length, label, cmdline_strlcpy, 
cmdline_strlcat) \
+   __cmdline_add_builtin_custom(dest, src, length, cmdline_strlcpy)
+#define cmdline_add_builtin(dest, src, length) \
+   __cmdline_add_builtin_custom(dest, src, length, strlcpy)
+#endif /* !CONFIG_CMDLINE_OVERRIDE */
+
+#else /* !CONFIG_GENERIC_CMDLINE || !CONFIG_CMDLINE_BOOL */
+
+#define CMDLINE_PREPEND ""
+#define CM

[PATCH 2/8] CMDLINE: drivers: of: ifdef out cmdline section

2021-03-30 Thread Daniel Walker
It looks like there's some seepage of cmdline stuff into
the generic device tree code. This conflicts with the
generic cmdline implementation so I remove it in the case
when that's enabled.

Cc: xe-linux-exter...@cisco.com
Signed-off-by: Ruslan Ruslichenko 
Signed-off-by: Daniel Walker 
---
 drivers/of/fdt.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index dcc1dd96911a..d8805cd9717a 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -25,6 +25,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include   /* for COMMAND_LINE_SIZE */
 #include 
@@ -1050,6 +1051,18 @@ int __init early_init_dt_scan_chosen(unsigned long node, 
const char *uname,
 
/* Retrieve command line */
p = of_get_flat_dt_prop(node, "bootargs", );
+
+#if defined(CONFIG_GENERIC_CMDLINE) && defined(CONFIG_GENERIC_CMDLINE_OF)
+   /*
+* The builtin command line will be added here, or it can override
+* with the DT bootargs.
+*/
+   cmdline_add_builtin(data,
+   (l > 0 ? p : NULL), /* This is sanity checking */
+   COMMAND_LINE_SIZE);
+#elif defined(CONFIG_GENERIC_CMDLINE)
+   strlcpy(data, p, COMMAND_LINE_SIZE);
+#else
if (p != NULL && l > 0)
strlcpy(data, p, min(l, COMMAND_LINE_SIZE));
 
@@ -1070,6 +1083,7 @@ int __init early_init_dt_scan_chosen(unsigned long node, 
const char *uname,
strlcpy(data, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
 #endif
 #endif /* CONFIG_CMDLINE */
+#endif /* CONFIG_GENERIC_CMDLINE */
 
pr_debug("Command line is: %s\n", (char *)data);
 
-- 
2.25.1



Re: [PATCH v2 3/7] powerpc: convert config files to generic cmdline

2021-03-30 Thread Daniel Walker
On Mon, Mar 29, 2021 at 11:07:51AM +0100, Will Deacon wrote:
> On Thu, Mar 25, 2021 at 12:59:56PM -0700, Daniel Walker wrote:
> > On Thu, Mar 25, 2021 at 01:03:55PM +0100, Christophe Leroy wrote:
> > > 
> > > Ok, so you agree we don't need to provide two CMDLINE, one to be appended 
> > > and one to be prepended.
> > > 
> > > Let's only provide once CMDLINE as of today, and ask the user to select
> > > whether he wants it appended or prepended or replacee. Then no need to
> > > change all existing config to rename CONFIG_CMDLINE into either of the new
> > > ones.
> > > 
> > > That's the main difference between my series and Daniel's series. So I'll
> > > finish taking Will's comment into account and we'll send out a v3 soon.
> > 
> > It doesn't solve the needs of Cisco, I've stated many times your changes 
> > have
> > little value. Please stop submitting them.
> 
> FWIW, they're useful for arm64 and I will gladly review the updated series.
> 
> I don't think asking people to stop submitting patches is ever the right
> answer. Please don't do that.

Why ? It's me nacking his series, is that not allowed anymore ?

Daniel


Re: [PATCH v2 3/7] powerpc: convert config files to generic cmdline

2021-03-30 Thread Daniel Walker
On Thu, Mar 25, 2021 at 05:29:44PM -0600, Rob Herring wrote:
> On Thu, Mar 25, 2021 at 2:00 PM Daniel Walker  wrote:
> >
> > On Thu, Mar 25, 2021 at 01:03:55PM +0100, Christophe Leroy wrote:
> > >
> > > Ok, so you agree we don't need to provide two CMDLINE, one to be appended 
> > > and one to be prepended.
> > >
> > > Let's only provide once CMDLINE as of today, and ask the user to select
> > > whether he wants it appended or prepended or replacee. Then no need to
> > > change all existing config to rename CONFIG_CMDLINE into either of the new
> > > ones.
> > >
> > > That's the main difference between my series and Daniel's series. So I'll
> > > finish taking Will's comment into account and we'll send out a v3 soon.
> >
> > It doesn't solve the needs of Cisco, I've stated many times your changes 
> > have
> > little value. Please stop submitting them.
> 
> Can you please outline what those needs are which aren't met?

append AND prepend at the same time on all architectures. Christophe doesn't
understand the need, and hence tries to minimize the feature set which is
incompatible with Cisco needs and all the other out of tree users.

Daniel


Re: [PATCH v3 01/17] cmdline: Add generic function to build command line.

2021-03-30 Thread Daniel Walker
On Fri, Mar 26, 2021 at 01:44:48PM +, Christophe Leroy wrote:
> This code provides architectures with a way to build command line
> based on what is built in the kernel and what is handed over by the
> bootloader, based on selected compile-time options.
> 
> Signed-off-by: Christophe Leroy 
> ---
> v3:
> - Addressed comments from Will
> - Added capability to have src == dst
> ---
>  include/linux/cmdline.h | 57 +
>  1 file changed, 57 insertions(+)
>  create mode 100644 include/linux/cmdline.h
> 
> diff --git a/include/linux/cmdline.h b/include/linux/cmdline.h
> new file mode 100644
> index ..dea87edd41be
> --- /dev/null
> +++ b/include/linux/cmdline.h
> @@ -0,0 +1,57 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +#ifndef _LINUX_CMDLINE_H
> +#define _LINUX_CMDLINE_H
> +
> +#include 
> +
> +/* Allow architectures to override strlcat, powerpc can't use strings so 
> early */
> +#ifndef cmdline_strlcat
> +#define cmdline_strlcat strlcat
> +#endif
> +
> +/*
> + * This function will append or prepend a builtin command line to the command
> + * line provided by the bootloader. Kconfig options can be used to alter
> + * the behavior of this builtin command line.
> + * @dst: The destination of the final appended/prepended string.
> + * @src: The starting string or NULL if there isn't one.
> + * @len: the length of dest buffer.
> + */

Append or prepend ? Cisco requires both at the same time. This is why my
implementation provides both. I can't use this with both at once.

Daniel


Re: [PATCH v2 4/7] CMDLINE: powerpc: convert to generic builtin command line

2021-03-25 Thread Daniel Walker
On Wed, Mar 24, 2021 at 04:31:35PM +0100, Christophe Leroy wrote:
> 
> 
> Le 09/03/2021 à 22:40, Daniel Walker a écrit :
> > On Tue, Mar 09, 2021 at 08:56:47AM +0100, Christophe Leroy wrote:
> > > 
> > > 
> > > Le 09/03/2021 à 01:02, Daniel Walker a écrit :
> > > > This updates the powerpc code to use the CONFIG_GENERIC_CMDLINE
> > > > option.
> > > > 
> > > > Cc: xe-linux-exter...@cisco.com
> > > > Signed-off-by: Ruslan Ruslichenko 
> > > > Signed-off-by: Ruslan Bilovol 
> > > > Signed-off-by: Daniel Walker 
> > > > ---
> > > >arch/powerpc/Kconfig| 37 
> > > > +
> > > >arch/powerpc/kernel/prom.c  |  1 +
> > > >arch/powerpc/kernel/prom_init.c | 35 ++-
> > > >3 files changed, 23 insertions(+), 50 deletions(-)
> > > > 
> > > > diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
> > > > index 107bb4319e0e..276b06d5c961 100644
> > > > --- a/arch/powerpc/Kconfig
> > > > +++ b/arch/powerpc/Kconfig
> > > > @@ -167,6 +167,7 @@ config PPC
> > > > select EDAC_SUPPORT
> > > > select GENERIC_ATOMIC64 if PPC32
> > > > select GENERIC_CLOCKEVENTS_BROADCASTif SMP
> > > > +   select GENERIC_CMDLINE
> > > > select GENERIC_CMOS_UPDATE
> > > > select GENERIC_CPU_AUTOPROBE
> > > > select GENERIC_CPU_VULNERABILITIES  if PPC_BARRIER_NOSPEC
> > > > @@ -906,42 +907,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
> > > > -   string "Initial kernel command string"
> > > > -   default ""
> > > > -   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.
> > > > -
> > > > -choice
> > > > -   prompt "Kernel command line type" if CMDLINE != ""
> > > > -   default CMDLINE_FROM_BOOTLOADER
> > > > -
> > > > -config CMDLINE_FROM_BOOTLOADER
> > > > -   bool "Use bootloader kernel arguments if available"
> > > > -   help
> > > > - Uses the command-line options passed by the boot loader. If
> > > > - the boot loader doesn't provide any, the default kernel 
> > > > command
> > > > - string provided in CMDLINE will be used.
> 
> I can't see how the above is supported in the generic builtin.
> 
> Taking into account that it is the default on powerpc, I'm having hardtime 
> with that.

Hmm, so this ignores the built in changes. You just don't enable it, or you
don't add PREPEND or APPEND.

> Any feedback on the proposed changes I made on the 13th ? I know it is
> partly buggy but that was more for the principle. I can make clean working
> patch if it helps.


The reason I added it into the function parameters is because I can get free
type checking on the functions. If you use macro's then you don't know if the
function is compatible.

Daniel


Re: [PATCH v2 3/7] powerpc: convert config files to generic cmdline

2021-03-25 Thread Daniel Walker
On Thu, Mar 25, 2021 at 01:03:55PM +0100, Christophe Leroy wrote:
> 
> Ok, so you agree we don't need to provide two CMDLINE, one to be appended and 
> one to be prepended.
> 
> Let's only provide once CMDLINE as of today, and ask the user to select
> whether he wants it appended or prepended or replacee. Then no need to
> change all existing config to rename CONFIG_CMDLINE into either of the new
> ones.
> 
> That's the main difference between my series and Daniel's series. So I'll
> finish taking Will's comment into account and we'll send out a v3 soon.

It doesn't solve the needs of Cisco, I've stated many times your changes have
little value. Please stop submitting them.

Daniel



Re: [PATCH v2 3/7] powerpc: convert config files to generic cmdline

2021-03-25 Thread Daniel Walker
On Wed, Mar 24, 2021 at 05:59:59PM +0100, Christophe Leroy wrote:
> > I think my changes maintain most of this due to the override of
> > CONFIG_CMDLINE_PREPEND. This is an upgrade and the inflexibility in powerpc 
> > is
> > an example of why these changes were created in the first place.
> 
> "inflexibility in powerpc" : Can you elaborate ?
 
the prom environment.

> > 
> > For example , say the default command line is "root=/dev/issblk0" from 
> > iss476
> > platform. And the bootloader adds "root=/dev/sda1"
> > 
> > The result is .
> 
> 
> I'm still having hard time understanding the benefit of having both  
> and .
> Could you please provide a complete exemple from real life, ie what exactly
> the problem is and what it solves ?
 
Say the boot loader of an old product is released with a command line of
"root=/dev/sda" and per the needs of the company or product the boot loader can
not be upgraded to change this command line. To change this behavior you would
need append or EXTEND.

Below I detail an example of PREPEND due to your list question.

> > 
> > Then you have,
> > 
> > root=/dev/issblk0 root=/dev/sda1
> > 
> > and the bootloader has precedent over the default command line. So root= in 
> > the
> > above cases is defined by the bootloader.

A person could input a command line into a boot loader, and it would override
the PREPEND values.

Can you imagine you have a default command line which makes root=/dev/issblk0 ,
but that doesn't work for you testing purpose. So you input into the boot loader
root=/dev/sda1 , since you have the default input in the bootloader OVERRIDEABLE
you can do this without re-compiling and just input the single root= command
into the bootloader.

Daniel


Re: [PATCH v2 4/7] CMDLINE: powerpc: convert to generic builtin command line

2021-03-09 Thread Daniel Walker
On Tue, Mar 09, 2021 at 08:56:47AM +0100, Christophe Leroy wrote:
> 
> 
> Le 09/03/2021 à 01:02, Daniel Walker a écrit :
> > This updates the powerpc code to use the CONFIG_GENERIC_CMDLINE
> > option.
> > 
> > Cc: xe-linux-exter...@cisco.com
> > Signed-off-by: Ruslan Ruslichenko 
> > Signed-off-by: Ruslan Bilovol 
> > Signed-off-by: Daniel Walker 
> > ---
> >   arch/powerpc/Kconfig| 37 +
> >   arch/powerpc/kernel/prom.c  |  1 +
> >   arch/powerpc/kernel/prom_init.c | 35 ++-
> >   3 files changed, 23 insertions(+), 50 deletions(-)
> > 
> > diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
> > index 107bb4319e0e..276b06d5c961 100644
> > --- a/arch/powerpc/Kconfig
> > +++ b/arch/powerpc/Kconfig
> > @@ -167,6 +167,7 @@ config PPC
> > select EDAC_SUPPORT
> > select GENERIC_ATOMIC64 if PPC32
> > select GENERIC_CLOCKEVENTS_BROADCASTif SMP
> > +   select GENERIC_CMDLINE
> > select GENERIC_CMOS_UPDATE
> > select GENERIC_CPU_AUTOPROBE
> > select GENERIC_CPU_VULNERABILITIES  if PPC_BARRIER_NOSPEC
> > @@ -906,42 +907,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
> > -   string "Initial kernel command string"
> > -   default ""
> > -   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.
> > -
> > -choice
> > -   prompt "Kernel command line type" if CMDLINE != ""
> > -   default CMDLINE_FROM_BOOTLOADER
> > -
> > -config CMDLINE_FROM_BOOTLOADER
> > -   bool "Use bootloader kernel arguments if available"
> > -   help
> > - Uses the command-line options passed by the boot loader. If
> > - the boot loader doesn't provide any, the default kernel command
> > - string provided in CMDLINE will be used.
> > -
> > -config CMDLINE_EXTEND
> > -   bool "Extend bootloader kernel arguments"
> > -   help
> > - The command-line arguments provided by the boot loader will be
> > - appended to the default kernel command string.
> > -
> > -config CMDLINE_FORCE
> > -   bool "Always use the default kernel command string"
> > -   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.
> > -
> > -endchoice
> > -
> >   config EXTRA_TARGETS
> > string "Additional default image types"
> > help
> > diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c
> > index ae3c41730367..96d0a01be1b4 100644
> > --- a/arch/powerpc/kernel/prom.c
> > +++ b/arch/powerpc/kernel/prom.c
> > @@ -27,6 +27,7 @@
> >   #include 
> >   #include 
> >   #include 
> > +#include 
> 
> Why is this needed in prom.c ?
 
Must have been a mistake, I don't think it's needed.


> >   #include 
> >   #include 
> >   #include 
> > diff --git a/arch/powerpc/kernel/prom_init.c 
> > b/arch/powerpc/kernel/prom_init.c
> > index e9d4eb6144e1..657241534d69 100644
> > --- a/arch/powerpc/kernel/prom_init.c
> > +++ b/arch/powerpc/kernel/prom_init.c
> > @@ -27,6 +27,7 @@
> >   #include 
> >   #include 
> >   #include 
> > +#include 
> >   #include 
> >   #include 
> >   #include 
> > @@ -242,15 +243,6 @@ static int __init prom_strcmp(const char *cs, const 
> > char *ct)
> > return 0;
> >   }
> > -static char __init *prom_strcpy(char *dest, const char *src)
> > -{
> > -   char *tmp = dest;
> > -
> > -   while ((*dest++ = *src++) != '\0')
> > -   /* nothing */;
> > -   return tmp;
> > -}
> > -
> 
> This game with prom_strcpy() should go a separate preceeding patch.
> 
> Also, it looks like checkpatch.pl recommends to use strscpy() instead of 
> strlcpy().

strscpy() is very large. I'm not sure it's compatible with this prom_init.c
environment.

> >   static int __init prom_strncmp(co

Re: [PATCH v2 3/7] powerpc: convert config files to generic cmdline

2021-03-09 Thread Daniel Walker
On Tue, Mar 09, 2021 at 08:47:09AM +0100, Christophe Leroy wrote:
> 
> 
> Le 09/03/2021 à 01:02, Daniel Walker a écrit :
> > This is a scripted mass convert of the config files to use
> > the new generic cmdline. There is a bit of a trim effect here.
> > It would seems that some of the config haven't been trimmed in
> > a while.
> 
> If you do that in a separate patch, you loose bisectability.
> 
> I think it would have been better to do things in a different way, more or 
> less like I did in my series:
> 1/ Provide GENERIC cmdline at the same functionnality level as what is
> spread in the different architectures
> 2/ Convert architectures to the generic with least churn.
> 3/ Add new features to the generic

You have to have the churn eventually, no matter how you do it. The only way you
don't have churn is if you never upgrade the feature set.


> > 
> > The bash script used to convert is as follows,
> > 
> > if [[ -z "$1" || -z "$2" ]]; then
> >  echo "Two arguments are needed."
> >  exit 1
> > fi
> > mkdir $1
> > cp $2 $1/.config
> > sed -i 's/CONFIG_CMDLINE=/CONFIG_CMDLINE_BOOL=y\nCONFIG_CMDLINE_PREPEND=/g' 
> > $1/.config
> 
> This is not correct.
> 
> By default, on powerpc the provided command line is used only if the 
> bootloader doesn't provide one.
> 
> Otherwise:
> - the builtin command line is appended to the one provided by the bootloader
> if CONFIG_CMDLINE_EXTEND is selected
> - the builtin command line replaces to the one provided by the bootloader if
> CONFIG_CMDLINE_FORCE is selected

I think my changes maintain most of this due to the override of
CONFIG_CMDLINE_PREPEND. This is an upgrade and the inflexibility in powerpc is
an example of why these changes were created in the first place.

For example , say the default command line is "root=/dev/issblk0" from iss476
platform. And the bootloader adds "root=/dev/sda1"

The result is .

Then you have,

root=/dev/issblk0 root=/dev/sda1

and the bootloader has precedent over the default command line. So root= in the
above cases is defined by the bootloader.

The only issue would be if a person wants to override the default command line
with an unrelated bootloader command line. I don't know how many people do this,
but I doubt it's many. Can you think of any use cases like this?

I would imagine there are many more people who have to entirely duplicate the
default command line in the boot loader when they really just want to change a
single part of it like the root= device or console device or speed.

Daniel


[PATCH v2 5/7] mips: convert config files to generic cmdline

2021-03-08 Thread Daniel Walker
This is a scripted mass convert of the config files to use
the new generic cmdline. There is a bit of a trim effect here.
It would seems that some of the config haven't been trimmed in
a while.

The script used is as follows,

if [[ -z "$1" || -z "$2" ]]; then
echo "Two arguments are needed."
exit 1
fi
mkdir $1
cp $2 $1/.config
sed -i 's/CONFIG_CMDLINE=/CONFIG_CMDLINE_BOOL=y\nCONFIG_CMDLINE_PREPEND=/g' 
$1/.config
make ARCH=$1 O=$1 olddefconfig
make ARCH=$1 O=$1 savedefconfig
cp $1/defconfig $2
rm -Rf $1

Cc: xe-linux-exter...@cisco.com
Signed-off-by: Daniel Walker 
---
 arch/mips/configs/ar7_defconfig|  9 ++---
 arch/mips/configs/bcm47xx_defconfig|  8 
 arch/mips/configs/bcm63xx_defconfig| 15 +--
 arch/mips/configs/bmips_be_defconfig   | 11 ---
 arch/mips/configs/bmips_stb_defconfig  | 11 ---
 arch/mips/configs/capcella_defconfig   | 11 ++-
 arch/mips/configs/ci20_defconfig   | 10 --
 arch/mips/configs/cu1000-neo_defconfig | 10 --
 arch/mips/configs/cu1830-neo_defconfig | 10 --
 arch/mips/configs/e55_defconfig|  4 ++--
 arch/mips/configs/generic_defconfig|  6 ++
 arch/mips/configs/gpr_defconfig| 18 +++---
 arch/mips/configs/loongson3_defconfig  | 13 ++---
 arch/mips/configs/mpc30x_defconfig |  7 ++-
 arch/mips/configs/tb0219_defconfig |  7 ++-
 arch/mips/configs/tb0226_defconfig |  7 ++-
 arch/mips/configs/tb0287_defconfig |  7 ++-
 arch/mips/configs/workpad_defconfig| 11 ---
 18 files changed, 54 insertions(+), 121 deletions(-)

diff --git a/arch/mips/configs/ar7_defconfig b/arch/mips/configs/ar7_defconfig
index cf9c6329b807..c09470aa672f 100644
--- a/arch/mips/configs/ar7_defconfig
+++ b/arch/mips/configs/ar7_defconfig
@@ -12,6 +12,8 @@ CONFIG_EXPERT=y
 # CONFIG_VM_EVENT_COUNTERS is not set
 # CONFIG_COMPAT_BRK is not set
 CONFIG_SLAB=y
+CONFIG_CMDLINE_BOOL=y
+CONFIG_CMDLINE_PREPEND="rootfstype=squashfs,jffs2"
 CONFIG_AR7=y
 CONFIG_HZ_100=y
 CONFIG_KEXEC=y
@@ -32,9 +34,6 @@ CONFIG_IP_ROUTE_MULTIPATH=y
 CONFIG_IP_ROUTE_VERBOSE=y
 CONFIG_IP_MROUTE=y
 CONFIG_SYN_COOKIES=y
-# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
-# CONFIG_INET_XFRM_MODE_TUNNEL is not set
-# CONFIG_INET_XFRM_MODE_BEET is not set
 # CONFIG_INET_DIAG is not set
 CONFIG_TCP_CONG_ADVANCED=y
 # CONFIG_TCP_CONG_BIC is not set
@@ -43,7 +42,6 @@ CONFIG_TCP_CONG_WESTWOOD=y
 # CONFIG_TCP_CONG_HTCP is not set
 # CONFIG_IPV6 is not set
 CONFIG_NETFILTER=y
-# CONFIG_BRIDGE_NETFILTER is not set
 CONFIG_NF_CONNTRACK=m
 CONFIG_NF_CONNTRACK_MARK=y
 CONFIG_NF_CONNTRACK_FTP=m
@@ -117,8 +115,5 @@ CONFIG_JFFS2_SUMMARY=y
 CONFIG_JFFS2_COMPRESSION_OPTIONS=y
 CONFIG_SQUASHFS=y
 # CONFIG_CRYPTO_HW is not set
-# CONFIG_ENABLE_MUST_CHECK is not set
 CONFIG_STRIP_ASM_SYMS=y
 CONFIG_DEBUG_FS=y
-CONFIG_CMDLINE_BOOL=y
-CONFIG_CMDLINE="rootfstype=squashfs,jffs2"
diff --git a/arch/mips/configs/bcm47xx_defconfig 
b/arch/mips/configs/bcm47xx_defconfig
index 91ce75edbfb4..69a965bb2dd9 100644
--- a/arch/mips/configs/bcm47xx_defconfig
+++ b/arch/mips/configs/bcm47xx_defconfig
@@ -4,8 +4,9 @@ CONFIG_BLK_DEV_INITRD=y
 CONFIG_CC_OPTIMIZE_FOR_SIZE=y
 CONFIG_EMBEDDED=y
 CONFIG_SLAB=y
+CONFIG_CMDLINE_BOOL=y
+CONFIG_CMDLINE_PREPEND="console=ttyS0,115200"
 CONFIG_BCM47XX=y
-CONFIG_PCI=y
 # CONFIG_SUSPEND is not set
 CONFIG_MODULES=y
 CONFIG_MODULE_UNLOAD=y
@@ -32,6 +33,7 @@ CONFIG_NET_SCH_FQ_CODEL=y
 CONFIG_HAMRADIO=y
 CONFIG_CFG80211=y
 CONFIG_MAC80211=y
+CONFIG_PCI=y
 CONFIG_MTD=y
 CONFIG_MTD_BCM47XX_PARTS=y
 CONFIG_MTD_BLOCK=y
@@ -75,7 +77,5 @@ CONFIG_PRINTK_TIME=y
 CONFIG_DEBUG_INFO=y
 CONFIG_DEBUG_INFO_REDUCED=y
 CONFIG_STRIP_ASM_SYMS=y
-CONFIG_DEBUG_FS=y
 CONFIG_MAGIC_SYSRQ=y
-CONFIG_CMDLINE_BOOL=y
-CONFIG_CMDLINE="console=ttyS0,115200"
+CONFIG_DEBUG_FS=y
diff --git a/arch/mips/configs/bcm63xx_defconfig 
b/arch/mips/configs/bcm63xx_defconfig
index 861f680184b9..6791e48b2d7d 100644
--- a/arch/mips/configs/bcm63xx_defconfig
+++ b/arch/mips/configs/bcm63xx_defconfig
@@ -11,27 +11,26 @@ CONFIG_EXPERT=y
 # CONFIG_AIO is not set
 # CONFIG_VM_EVENT_COUNTERS is not set
 # CONFIG_SLUB_DEBUG is not set
+CONFIG_CMDLINE_BOOL=y
+CONFIG_CMDLINE_PREPEND="console=ttyS0,115200"
 CONFIG_BCM63XX=y
 CONFIG_BCM63XX_CPU_6338=y
 CONFIG_BCM63XX_CPU_6345=y
 CONFIG_BCM63XX_CPU_6348=y
 CONFIG_BCM63XX_CPU_6358=y
 # CONFIG_SECCOMP is not set
-CONFIG_PCI=y
-CONFIG_PCCARD=y
-CONFIG_PCMCIA_BCM63XX=y
 # CONFIG_BLK_DEV_BSG is not set
 CONFIG_NET=y
 CONFIG_UNIX=y
 CONFIG_INET=y
-# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
-# CONFIG_INET_XFRM_MODE_TUNNEL is not set
-# CONFIG_INET_XFRM_MODE_BEET is not set
 # CONFIG_INET_DIAG is not set
 # CONFIG_IPV6 is not set
 CONFIG_CFG80211=y
 CONFIG_NL80211_TESTMODE=y
 CONFIG_MAC80211=y
+CONFIG_PCI=y
+CONFIG_PCCARD=y
+CONFIG_PCMCIA_BCM63XX=y
 # CONFIG_STANDALONE is not set
 # CONFIG_PREVENT_FIRMWA

[PATCH v2 6/7] CMDLINE: mips: convert to generic builtin command line

2021-03-08 Thread Daniel Walker
This updates the mips code to use the CONFIG_GENERIC_CMDLINE
option.

This deletes the option for MIPS_CMDLINE_BUILTIN_EXTEND
and replaces the functionality with generic code.

Cc: xe-linux-exter...@cisco.com
Signed-off-by: Ruslan Ruslichenko 
Signed-off-by: Ruslan Bilovol 
Signed-off-by: Daniel Walker 
---
 arch/mips/Kconfig|  4 +---
 arch/mips/Kconfig.debug  | 44 
 arch/mips/kernel/setup.c | 36 
 3 files changed, 5 insertions(+), 79 deletions(-)

diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index 0a17bedf4f0d..7c07b3bca9fc 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -23,6 +23,7 @@ config MIPS
select CPU_NO_EFFICIENT_FFS if (TARGET_ISA_REV < 1)
select CPU_PM if CPU_IDLE
select GENERIC_ATOMIC64 if !64BIT
+   select GENERIC_CMDLINE
select GENERIC_CMOS_UPDATE
select GENERIC_CPU_AUTOPROBE
select GENERIC_GETTIMEOFDAY
@@ -3171,9 +3172,6 @@ choice
config MIPS_CMDLINE_FROM_BOOTLOADER
bool "Bootloader kernel arguments if available"
 
-   config MIPS_CMDLINE_BUILTIN_EXTEND
-   depends on CMDLINE_BOOL
-   bool "Extend builtin kernel arguments with bootloader arguments"
 endchoice
 
 endmenu
diff --git a/arch/mips/Kconfig.debug b/arch/mips/Kconfig.debug
index 7a8d94cdd493..b5a099c74eb6 100644
--- a/arch/mips/Kconfig.debug
+++ b/arch/mips/Kconfig.debug
@@ -30,50 +30,6 @@ config EARLY_PRINTK_8250
 config USE_GENERIC_EARLY_PRINTK_8250
bool
 
-config CMDLINE_BOOL
-   bool "Built-in kernel command line"
-   help
- For most systems, it is firmware or second stage bootloader that
- by default specifies the kernel command line options.  However,
- it might be necessary or advantageous to either override the
- default kernel command line or add a few extra options to it.
- For such cases, this option allows you to hardcode your own
- command line options directly into the kernel.  For that, you
- should choose 'Y' here, and fill in the extra boot arguments
- in CONFIG_CMDLINE.
-
- The built-in options will be concatenated to the default command
- line if CMDLINE_OVERRIDE is set to 'N'. Otherwise, the default
- command line will be ignored and replaced by the built-in string.
-
- Most MIPS systems will normally expect 'N' here and rely upon
- the command line from the firmware or the second-stage bootloader.
-
-config CMDLINE
-   string "Default kernel command string"
-   depends on CMDLINE_BOOL
-   help
- On some platforms, there is currently no way for the boot loader to
- pass arguments to the kernel.  For these platforms, and for the cases
- when you want to add some extra options to the command line or ignore
- the default command line, you can supply some command-line options at
- build time by entering them here.  In other cases you can specify
- kernel args so that you don't have to set them up in board prom
- initialization routines.
-
- For more information, see the CMDLINE_BOOL and CMDLINE_OVERRIDE
- options.
-
-config CMDLINE_OVERRIDE
-   bool "Built-in command line overrides firmware arguments"
-   depends on CMDLINE_BOOL
-   help
- By setting this option to 'Y' you will have your kernel ignore
- command line arguments from firmware or second stage bootloader.
- Instead, the built-in command line will be used exclusively.
-
- Normally, you will choose 'N' here.
-
 config SB1XXX_CORELIS
bool "Corelis Debugger"
depends on SIBYTE_SB1xxx_SOC
diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c
index 7e1f8e277437..8ce763e03792 100644
--- a/arch/mips/kernel/setup.c
+++ b/arch/mips/kernel/setup.c
@@ -23,6 +23,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -67,12 +68,6 @@ EXPORT_SYMBOL(mips_machtype);
 static char __initdata command_line[COMMAND_LINE_SIZE];
 char __initdata arcs_cmdline[COMMAND_LINE_SIZE];
 
-#ifdef CONFIG_CMDLINE_BOOL
-static const char builtin_cmdline[] __initconst = CONFIG_CMDLINE;
-#else
-static const char builtin_cmdline[] __initconst = "";
-#endif
-
 /*
  * mips_io_port_base is the begin of the address space to which x86 style
  * I/O ports are mapped.
@@ -546,27 +541,7 @@ static void __init bootcmdline_init(void)
 {
bool dt_bootargs = false;
 
-   /*
-* If CMDLINE_OVERRIDE is enabled then initializing the command line is
-* trivial - we simply use the built-in command line unconditionally &
-* unmodified.
-*/
-   if (IS_ENABLED(CONFIG_CMDLINE_OVERRIDE)) {
-   strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
-   return;
- 

[PATCH v2 4/7] CMDLINE: powerpc: convert to generic builtin command line

2021-03-08 Thread Daniel Walker
This updates the powerpc code to use the CONFIG_GENERIC_CMDLINE
option.

Cc: xe-linux-exter...@cisco.com
Signed-off-by: Ruslan Ruslichenko 
Signed-off-by: Ruslan Bilovol 
Signed-off-by: Daniel Walker 
---
 arch/powerpc/Kconfig| 37 +
 arch/powerpc/kernel/prom.c  |  1 +
 arch/powerpc/kernel/prom_init.c | 35 ++-
 3 files changed, 23 insertions(+), 50 deletions(-)

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 107bb4319e0e..276b06d5c961 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -167,6 +167,7 @@ config PPC
select EDAC_SUPPORT
select GENERIC_ATOMIC64 if PPC32
select GENERIC_CLOCKEVENTS_BROADCASTif SMP
+   select GENERIC_CMDLINE
select GENERIC_CMOS_UPDATE
select GENERIC_CPU_AUTOPROBE
select GENERIC_CPU_VULNERABILITIES  if PPC_BARRIER_NOSPEC
@@ -906,42 +907,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
-   string "Initial kernel command string"
-   default ""
-   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.
-
-choice
-   prompt "Kernel command line type" if CMDLINE != ""
-   default CMDLINE_FROM_BOOTLOADER
-
-config CMDLINE_FROM_BOOTLOADER
-   bool "Use bootloader kernel arguments if available"
-   help
- Uses the command-line options passed by the boot loader. If
- the boot loader doesn't provide any, the default kernel command
- string provided in CMDLINE will be used.
-
-config CMDLINE_EXTEND
-   bool "Extend bootloader kernel arguments"
-   help
- The command-line arguments provided by the boot loader will be
- appended to the default kernel command string.
-
-config CMDLINE_FORCE
-   bool "Always use the default kernel command string"
-   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.
-
-endchoice
-
 config EXTRA_TARGETS
string "Additional default image types"
help
diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c
index ae3c41730367..96d0a01be1b4 100644
--- a/arch/powerpc/kernel/prom.c
+++ b/arch/powerpc/kernel/prom.c
@@ -27,6 +27,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/powerpc/kernel/prom_init.c b/arch/powerpc/kernel/prom_init.c
index e9d4eb6144e1..657241534d69 100644
--- a/arch/powerpc/kernel/prom_init.c
+++ b/arch/powerpc/kernel/prom_init.c
@@ -27,6 +27,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -242,15 +243,6 @@ static int __init prom_strcmp(const char *cs, const char 
*ct)
return 0;
 }
 
-static char __init *prom_strcpy(char *dest, const char *src)
-{
-   char *tmp = dest;
-
-   while ((*dest++ = *src++) != '\0')
-   /* nothing */;
-   return tmp;
-}
-
 static int __init prom_strncmp(const char *cs, const char *ct, size_t count)
 {
unsigned char c1, c2;
@@ -276,6 +268,20 @@ static size_t __init prom_strlen(const char *s)
return sc - s;
 }
 
+static size_t __init prom_strlcpy(char *dest, const char *src, size_t size)
+{
+   size_t ret = prom_strlen(src);
+
+   if (size) {
+   size_t len = (ret >= size) ? size - 1 : ret;
+
+   memcpy(dest, src, len);
+   dest[len] = '\0';
+   }
+   return ret;
+}
+
+
 static int __init prom_memcmp(const void *cs, const void *ct, size_t count)
 {
const unsigned char *su1, *su2;
@@ -304,6 +310,7 @@ static char __init *prom_strstr(const char *s1, const char 
*s2)
return NULL;
 }
 
+#ifdef GENERIC_CMDLINE_NEED_STRLCAT
 static size_t __init prom_strlcat(char *dest, const char *src, size_t count)
 {
size_t dsize = prom_strlen(dest);
@@ -323,6 +330,7 @@ static size_t __init prom_strlcat(char *dest, const char 
*src, size_t count)
return res;
 
 }
+#endif
 
 #ifdef CONFIG_PPC_PSERIES
 static int __init prom_strtobool(const char *s, bool *res)
@@ -775,12 +783,11 @@ static void __init early_cmdline_parse(void)
prom_cmd_line[0] = 0;
p = prom_cmd_line;
 
-   if (!IS_ENABLED(CONFIG_CMDLINE_FORCE) && (long)prom.chosen > 0)
+   if ((long)prom.chosen > 0)
l = prom_getprop(prom.chosen, "bootarg

[PATCH v2 7/7] CMDLINE: x86: convert to generic builtin command line

2021-03-08 Thread Daniel Walker
This updates the x86 code to use the CONFIG_GENERIC_CMDLINE
option.

Cc: xe-linux-exter...@cisco.com
Signed-off-by: Ruslan Ruslichenko 
Signed-off-by: Ruslan Bilovol 
Signed-off-by: Daniel Walker 
---
 arch/x86/Kconfig| 44 +
 arch/x86/kernel/setup.c | 18 ++
 drivers/firmware/efi/libstub/x86-stub.c |  2 +-
 3 files changed, 4 insertions(+), 60 deletions(-)

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 21f851179ff0..3950f9bf9855 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -115,6 +115,7 @@ config X86
select EDAC_SUPPORT
select GENERIC_CLOCKEVENTS_BROADCASTif X86_64 || (X86_32 && 
X86_LOCAL_APIC)
select GENERIC_CLOCKEVENTS_MIN_ADJUST
+   select GENERIC_CMDLINE
select GENERIC_CMOS_UPDATE
select GENERIC_CPU_AUTOPROBE
select GENERIC_CPU_VULNERABILITIES
@@ -2368,49 +2369,6 @@ choice
 
 endchoice
 
-config CMDLINE_BOOL
-   bool "Built-in kernel command line"
-   help
- Allow for specifying boot arguments to the kernel at
- build time.  On some systems (e.g. embedded ones), it is
- necessary or convenient to provide some or all of the
- kernel boot arguments with the kernel itself (that is,
- to not rely on the boot loader to provide them.)
-
- To compile command line arguments into the kernel,
- set this option to 'Y', then fill in the
- boot arguments in CONFIG_CMDLINE.
-
- Systems with fully functional boot loaders (i.e. non-embedded)
- should leave this option set to 'N'.
-
-config CMDLINE
-   string "Built-in kernel command string"
-   depends on CMDLINE_BOOL
-   default ""
-   help
- Enter arguments here that should be compiled into the kernel
- image and used at boot time.  If the boot loader provides a
- command line at boot time, it is appended to this string to
- form the full kernel command line, when the system boots.
-
- However, you can use the CONFIG_CMDLINE_OVERRIDE option to
- change this behavior.
-
- In most cases, the command line (whether built-in or provided
- by the boot loader) should specify the device for the root
- file system.
-
-config CMDLINE_OVERRIDE
-   bool "Built-in command line overrides boot loader arguments"
-   depends on CMDLINE_BOOL && CMDLINE != ""
-   help
- Set this option to 'Y' to have the kernel ignore the boot loader
- command line, and use ONLY the built-in command line.
-
- This is used to work around broken boot loaders.  This should
- be set to 'N' under normal conditions.
-
 config MODIFY_LDT_SYSCALL
bool "Enable the LDT (local descriptor table)" if EXPERT
default y
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index 740f3bdb3f61..e748c3e5c1ae 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -48,6 +48,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /*
  * max_low_pfn_mapped: highest directly mapped pfn < 4 GB
@@ -162,9 +163,6 @@ unsigned long saved_video_mode;
 #define RAMDISK_LOAD_FLAG  0x4000
 
 static char __initdata command_line[COMMAND_LINE_SIZE];
-#ifdef CONFIG_CMDLINE_BOOL
-static char __initdata builtin_cmdline[COMMAND_LINE_SIZE] = CONFIG_CMDLINE;
-#endif
 
 #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
 struct edd edd;
@@ -884,19 +882,7 @@ void __init setup_arch(char **cmdline_p)
bss_resource.start = __pa_symbol(__bss_start);
bss_resource.end = __pa_symbol(__bss_stop)-1;
 
-#ifdef CONFIG_CMDLINE_BOOL
-#ifdef CONFIG_CMDLINE_OVERRIDE
-   strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
-#else
-   if (builtin_cmdline[0]) {
-   /* append boot loader cmdline to builtin */
-   strlcat(builtin_cmdline, " ", COMMAND_LINE_SIZE);
-   strlcat(builtin_cmdline, boot_command_line, COMMAND_LINE_SIZE);
-   strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
-   }
-#endif
-#endif
-
+   cmdline_add_builtin(boot_command_line, NULL, COMMAND_LINE_SIZE);
strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
*cmdline_p = command_line;
 
diff --git a/drivers/firmware/efi/libstub/x86-stub.c 
b/drivers/firmware/efi/libstub/x86-stub.c
index f14c4ff5839f..9538c9d4a0bc 100644
--- a/drivers/firmware/efi/libstub/x86-stub.c
+++ b/drivers/firmware/efi/libstub/x86-stub.c
@@ -736,7 +736,7 @@ unsigned long efi_main(efi_handle_t handle,
}
 
 #ifdef CONFIG_CMDLINE_BOOL
-   status = efi_parse_options(CONFIG_CMDLINE);
+   status = efi_parse_options(CONFIG_CMDLINE_PREPEND " " 
CONFIG_CMDLINE_APPEND);
if (status != EFI_SUCCESS) {
efi_err("Failed to parse options\n");
goto fail;
-- 
2.25.1



[PATCH v2 0/7] Generic Command Line changes

2021-03-08 Thread Daniel Walker
This fixed some problem identified in my last release. I made updates
based on comments from Christophe Leroy.

I added scripted updates to the defconfig file for mips and powerpc.
This is required in order to maintain the status quo for those platforms
which used the prior builtin command line system.

These were tested on all effected architectures.

Daniel Walker (7):
  CMDLINE: add generic builtin command line
  CMDLINE: drivers: of: ifdef out cmdline section
  powerpc: convert config files to generic cmdline
  CMDLINE: powerpc: convert to generic builtin command line
  mips: convert config files to generic cmdline
  CMDLINE: mips: convert to generic builtin command line
  CMDLINE: x86: convert to generic builtin command line

 arch/mips/Kconfig |  4 +-
 arch/mips/Kconfig.debug   | 44 -
 arch/mips/configs/ar7_defconfig   |  9 +-
 arch/mips/configs/bcm47xx_defconfig   |  8 +-
 arch/mips/configs/bcm63xx_defconfig   | 15 ++--
 arch/mips/configs/bmips_be_defconfig  | 11 +--
 arch/mips/configs/bmips_stb_defconfig | 11 +--
 arch/mips/configs/capcella_defconfig  | 11 +--
 arch/mips/configs/ci20_defconfig  | 10 +--
 arch/mips/configs/cu1000-neo_defconfig| 10 +--
 arch/mips/configs/cu1830-neo_defconfig| 10 +--
 arch/mips/configs/e55_defconfig   |  4 +-
 arch/mips/configs/generic_defconfig   |  6 +-
 arch/mips/configs/gpr_defconfig   | 18 +---
 arch/mips/configs/loongson3_defconfig | 13 +--
 arch/mips/configs/mpc30x_defconfig|  7 +-
 arch/mips/configs/tb0219_defconfig|  7 +-
 arch/mips/configs/tb0226_defconfig|  7 +-
 arch/mips/configs/tb0287_defconfig|  7 +-
 arch/mips/configs/workpad_defconfig   | 11 +--
 arch/mips/kernel/setup.c  | 36 +---
 arch/powerpc/Kconfig  | 37 +---
 arch/powerpc/configs/44x/fsp2_defconfig   | 33 ---
 arch/powerpc/configs/44x/iss476-smp_defconfig | 25 +++---
 arch/powerpc/configs/44x/warp_defconfig   | 17 ++--
 arch/powerpc/configs/holly_defconfig  | 13 +--
 arch/powerpc/configs/mvme5100_defconfig   | 23 ++---
 arch/powerpc/configs/skiroot_defconfig| 12 ++-
 arch/powerpc/configs/storcenter_defconfig | 18 ++--
 arch/powerpc/kernel/prom.c|  1 +
 arch/powerpc/kernel/prom_init.c   | 35 +---
 arch/x86/Kconfig  | 44 +
 arch/x86/kernel/setup.c   | 18 +---
 drivers/firmware/efi/libstub/x86-stub.c   |  2 +-
 drivers/of/fdt.c  | 12 +++
 include/linux/cmdline.h   | 89 +++
 init/Kconfig  | 68 ++
 37 files changed, 321 insertions(+), 385 deletions(-)
 create mode 100644 include/linux/cmdline.h

-- 
2.25.1



[PATCH v2 3/7] powerpc: convert config files to generic cmdline

2021-03-08 Thread Daniel Walker
This is a scripted mass convert of the config files to use
the new generic cmdline. There is a bit of a trim effect here.
It would seems that some of the config haven't been trimmed in
a while.

The bash script used to convert is as follows,

if [[ -z "$1" || -z "$2" ]]; then
echo "Two arguments are needed."
exit 1
fi
mkdir $1
cp $2 $1/.config
sed -i 's/CONFIG_CMDLINE=/CONFIG_CMDLINE_BOOL=y\nCONFIG_CMDLINE_PREPEND=/g' 
$1/.config
make ARCH=$1 O=$1 olddefconfig
make ARCH=$1 O=$1 savedefconfig
cp $1/defconfig $2
rm -Rf $1

Cc: xe-linux-exter...@cisco.com
Signed-off-by: Daniel Walker 
---
 arch/powerpc/configs/44x/fsp2_defconfig   | 33 +--
 arch/powerpc/configs/44x/iss476-smp_defconfig | 25 +++---
 arch/powerpc/configs/44x/warp_defconfig   | 17 +-
 arch/powerpc/configs/holly_defconfig  | 13 
 arch/powerpc/configs/mvme5100_defconfig   | 23 ++---
 arch/powerpc/configs/skiroot_defconfig| 12 +++
 arch/powerpc/configs/storcenter_defconfig | 18 --
 7 files changed, 66 insertions(+), 75 deletions(-)

diff --git a/arch/powerpc/configs/44x/fsp2_defconfig 
b/arch/powerpc/configs/44x/fsp2_defconfig
index 30845ce0885a..4993db054589 100644
--- a/arch/powerpc/configs/44x/fsp2_defconfig
+++ b/arch/powerpc/configs/44x/fsp2_defconfig
@@ -1,8 +1,6 @@
-CONFIG_44x=y
 # CONFIG_SWAP is not set
 CONFIG_SYSVIPC=y
 # CONFIG_CROSS_MEMORY_ATTACH is not set
-# CONFIG_FHANDLE is not set
 CONFIG_NO_HZ=y
 CONFIG_HIGH_RES_TIMERS=y
 CONFIG_IKCONFIG=y
@@ -13,24 +11,25 @@ CONFIG_BLK_DEV_INITRD=y
 # CONFIG_RD_XZ is not set
 # CONFIG_RD_LZO is not set
 # CONFIG_RD_LZ4 is not set
+# CONFIG_FHANDLE is not set
 CONFIG_KALLSYMS_ALL=y
 CONFIG_BPF_SYSCALL=y
 CONFIG_EMBEDDED=y
 CONFIG_PROFILING=y
-CONFIG_OPROFILE=y
-CONFIG_MODULES=y
-CONFIG_MODULE_UNLOAD=y
-# CONFIG_BLK_DEV_BSG is not set
+CONFIG_CMDLINE_BOOL=y
+CONFIG_CMDLINE_PREPEND="ip=on rw"
+CONFIG_44x=y
 CONFIG_PPC_47x=y
 # CONFIG_EBONY is not set
 CONFIG_FSP2=y
 CONFIG_476FPE_ERR46=y
-CONFIG_SWIOTLB=y
 CONFIG_KEXEC=y
 CONFIG_CRASH_DUMP=y
-CONFIG_CMDLINE="ip=on rw"
 # CONFIG_SUSPEND is not set
-# CONFIG_PCI is not set
+CONFIG_OPROFILE=y
+CONFIG_MODULES=y
+CONFIG_MODULE_UNLOAD=y
+# CONFIG_BLK_DEV_BSG is not set
 CONFIG_NET=y
 CONFIG_PACKET=y
 CONFIG_UNIX=y
@@ -47,14 +46,12 @@ CONFIG_MTD=y
 CONFIG_MTD_BLOCK=y
 CONFIG_MTD_JEDECPROBE=y
 CONFIG_MTD_CFI_AMDSTD=y
-CONFIG_MTD_PHYSMAP_OF=y
 CONFIG_BLK_DEV_RAM=y
 CONFIG_BLK_DEV_RAM_SIZE=35000
 # CONFIG_SCSI_PROC_FS is not set
 CONFIG_BLK_DEV_SD=y
 # CONFIG_SCSI_LOWLEVEL is not set
 CONFIG_ATA=y
-# CONFIG_SATA_PMP is not set
 # CONFIG_ATA_SFF is not set
 CONFIG_NETDEVICES=y
 CONFIG_BONDING=m
@@ -63,7 +60,6 @@ CONFIG_IBM_EMAC=m
 # CONFIG_SERIO is not set
 # CONFIG_VT is not set
 # CONFIG_LEGACY_PTYS is not set
-# CONFIG_DEVMEM is not set
 CONFIG_SERIAL_8250=y
 CONFIG_SERIAL_8250_CONSOLE=y
 CONFIG_SERIAL_8250_NR_UARTS=32
@@ -72,6 +68,7 @@ CONFIG_SERIAL_8250_EXTENDED=y
 CONFIG_SERIAL_8250_SHARE_IRQ=y
 CONFIG_SERIAL_OF_PLATFORM=y
 # CONFIG_HW_RANDOM is not set
+# CONFIG_DEVMEM is not set
 CONFIG_I2C=y
 CONFIG_I2C_IBM_IIC=y
 CONFIG_PTP_1588_CLOCK=y
@@ -107,6 +104,12 @@ CONFIG_NFS_V3_ACL=y
 CONFIG_NFS_V4=y
 CONFIG_ROOT_NFS=y
 CONFIG_NLS_DEFAULT="n"
+CONFIG_CRYPTO_CBC=y
+CONFIG_CRYPTO_ECB=y
+CONFIG_CRYPTO_PCBC=y
+CONFIG_CRYPTO_MD5=y
+CONFIG_CRYPTO_DES=y
+# CONFIG_CRYPTO_HW is not set
 CONFIG_XZ_DEC=y
 CONFIG_PRINTK_TIME=y
 CONFIG_MESSAGE_LOGLEVEL_DEFAULT=3
@@ -114,9 +117,3 @@ CONFIG_DYNAMIC_DEBUG=y
 CONFIG_DEBUG_INFO=y
 CONFIG_MAGIC_SYSRQ=y
 CONFIG_DETECT_HUNG_TASK=y
-CONFIG_CRYPTO_CBC=y
-CONFIG_CRYPTO_ECB=y
-CONFIG_CRYPTO_PCBC=y
-CONFIG_CRYPTO_MD5=y
-CONFIG_CRYPTO_DES=y
-# CONFIG_CRYPTO_HW is not set
diff --git a/arch/powerpc/configs/44x/iss476-smp_defconfig 
b/arch/powerpc/configs/44x/iss476-smp_defconfig
index 2c3834eebca3..b8d97061517a 100644
--- a/arch/powerpc/configs/44x/iss476-smp_defconfig
+++ b/arch/powerpc/configs/44x/iss476-smp_defconfig
@@ -1,5 +1,3 @@
-CONFIG_44x=y
-CONFIG_SMP=y
 CONFIG_SYSVIPC=y
 CONFIG_POSIX_MQUEUE=y
 CONFIG_LOG_BUF_SHIFT=14
@@ -7,20 +5,22 @@ CONFIG_BLK_DEV_INITRD=y
 CONFIG_EXPERT=y
 CONFIG_KALLSYMS_ALL=y
 CONFIG_PROFILING=y
-CONFIG_OPROFILE=y
-CONFIG_MODULES=y
-CONFIG_MODULE_UNLOAD=y
-# CONFIG_BLK_DEV_BSG is not set
+CONFIG_CMDLINE_BOOL=y
+CONFIG_CMDLINE_PREPEND="root=/dev/issblk0"
+CONFIG_44x=y
+CONFIG_SMP=y
 CONFIG_PPC_47x=y
 # CONFIG_EBONY is not set
 CONFIG_ISS4xx=y
 CONFIG_HZ_100=y
 CONFIG_MATH_EMULATION=y
 CONFIG_IRQ_ALL_CPUS=y
-CONFIG_CMDLINE="root=/dev/issblk0"
-# CONFIG_PCI is not set
 CONFIG_ADVANCED_OPTIONS=y
 CONFIG_DYNAMIC_MEMSTART=y
+CONFIG_OPROFILE=y
+CONFIG_MODULES=y
+CONFIG_MODULE_UNLOAD=y
+# CONFIG_BLK_DEV_BSG is not set
 CONFIG_NET=y
 CONFIG_PACKET=y
 CONFIG_UNIX=y
@@ -34,7 +34,6 @@ CONFIG_MTD=y
 CONFIG_MTD_BLOCK=y
 CONFIG_MTD_JEDECPROBE=y
 CONFIG_MTD_CFI_AMDSTD=y
-CONFIG_MTD_PHYSMAP_OF=y
 CONFIG_BLK_DEV_RAM=y
 CONFIG_BLK_DEV_R

[PATCH v2 1/7] CMDLINE: add generic builtin command line

2021-03-08 Thread Daniel Walker
This code allows architectures to use a generic builtin command line.
The state of the builtin command line options across architecture is
diverse. On x86 and mips they have pretty much the same code and the
code prepends the builtin command line onto the boot loader provided
one. On powerpc there is only a builtin override and nothing else.

The code in this commit unifies the code into a generic
header file under the CONFIG_GENERIC_CMDLINE option. When this
option is enabled the architecture can call the cmdline_add_builtin()
to add the builtin command line.

Cc: xe-linux-exter...@cisco.com
Signed-off-by: Ruslan Bilovol 
Signed-off-by: Daniel Walker 
---
 include/linux/cmdline.h | 89 +
 init/Kconfig| 68 +++
 2 files changed, 157 insertions(+)
 create mode 100644 include/linux/cmdline.h

diff --git a/include/linux/cmdline.h b/include/linux/cmdline.h
new file mode 100644
index ..00929b6e49e6
--- /dev/null
+++ b/include/linux/cmdline.h
@@ -0,0 +1,89 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_CMDLINE_H
+#define _LINUX_CMDLINE_H
+
+/*
+ *
+ * Copyright (C) 2006,2021. Cisco Systems, Inc.
+ *
+ * Generic Append/Prepend cmdline support.
+ */
+
+#if defined(CONFIG_GENERIC_CMDLINE) && defined(CONFIG_CMDLINE_BOOL)
+
+#ifndef CONFIG_CMDLINE_OVERRIDE
+#define GENERIC_CMDLINE_NEED_STRLCAT
+/*
+ * This function will append or prepend a builtin command line to the command
+ * line provided by the bootloader. Kconfig options can be used to alter
+ * the behavior of this builtin command line.
+ * @dest: The destination of the final appended/prepended string
+ * @src: The starting string or NULL if there isn't one.
+ * @tmp: temporary space used for prepending
+ * @length: the maximum length of the strings above.
+ * @cmdline_strlcpy: point to a compatible strlcpy
+ * @cmdline_strlcat: point to a compatible strlcat
+ */
+static inline void
+__cmdline_add_builtin(char *dest, const char *src, char *tmp, unsigned long 
length,
+   size_t (*cmdline_strlcpy)(char *dest, const char *src, size_t 
size),
+   size_t (*cmdline_strlcat)(char *dest, const char *src, size_t 
count))
+{
+   if (src != dest && src != NULL) {
+   cmdline_strlcpy(dest, " ", length);
+   cmdline_strlcat(dest, src, length);
+   }
+
+   if (sizeof(CONFIG_CMDLINE_APPEND) > 1)
+   cmdline_strlcat(dest, " " CONFIG_CMDLINE_APPEND, length);
+
+   if (sizeof(CONFIG_CMDLINE_PREPEND) > 1) {
+   cmdline_strlcpy(tmp, CONFIG_CMDLINE_PREPEND " ", length);
+   cmdline_strlcat(tmp, dest, length);
+   cmdline_strlcpy(dest, tmp, length);
+   }
+}
+
+#define cmdline_add_builtin_custom(dest, src, length, label, cmdline_strlcpy, 
cmdline_strlcat) \
+{  
\
+   if (sizeof(CONFIG_CMDLINE_PREPEND) > 1) {   
\
+   static label char cmdline_tmp_space[length];
\
+   __cmdline_add_builtin(dest, src, cmdline_tmp_space, length, 
cmdline_strlcpy, cmdline_strlcat);  \
+   } else if (sizeof(CONFIG_CMDLINE_APPEND) > 1) { 
\
+   __cmdline_add_builtin(dest, src, NULL, length, cmdline_strlcpy, 
cmdline_strlcat);   \
+   }   
\
+}
+#define cmdline_add_builtin(dest, src, length) \
+   cmdline_add_builtin_custom(dest, src, length, __initdata, strlcpy, 
strlcat)
+
+#else /* CONFIG_CMDLINE_OVERRIDE */
+
+static inline void
+__cmdline_add_builtin_custom(char *dest, const char *src, unsigned long length,
+   size_t (*cmdline_strlcpy)(char *dest, const char *src, size_t 
size))
+{
+   cmdline_strlcpy(dest, CONFIG_CMDLINE_PREPEND " " CONFIG_CMDLINE_APPEND, 
length);
+}
+#define cmdline_add_builtin_custom(dest, src, length, label, cmdline_strlcpy, 
cmdline_strlcat) \
+   __cmdline_add_builtin_custom(dest, src, length, cmdline_strlcpy)
+#define cmdline_add_builtin(dest, src, length) \
+   __cmdline_add_builtin_custom(dest, src, length, strlcpy)
+#endif /* !CONFIG_CMDLINE_OVERRIDE */
+
+#else /* !CONFIG_GENERIC_CMDLINE || !CONFIG_CMDLINE_BOOL */
+
+static inline void
+__cmdline_add_builtin_custom(char *dest, const char *src, unsigned long length,
+   size_t (*cmdline_strlcpy)(char *dest, const char *src, size_t 
size))
+{
+   if (src != NULL)
+   cmdline_strlcpy(dest, src, length);
+}
+#define cmdline_add_builtin_custom(dest, src, length, label, cmdline_strlcpy, 
cmdline_strlcat) \
+   __cmdline_add_builtin_custom(d

[PATCH v2 2/7] CMDLINE: drivers: of: ifdef out cmdline section

2021-03-08 Thread Daniel Walker
It looks like there's some seepage of cmdline stuff into
the generic device tree code. This conflicts with the
generic cmdline implementation so I remove it in the case
when that's enabled.

Cc: xe-linux-exter...@cisco.com
Signed-off-by: Ruslan Ruslichenko 
Signed-off-by: Daniel Walker 
---
 drivers/of/fdt.c | 12 
 1 file changed, 12 insertions(+)

diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index feb0f2d67fc5..e25240d84632 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -25,6 +25,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include   /* for COMMAND_LINE_SIZE */
 #include 
@@ -1050,6 +1051,16 @@ int __init early_init_dt_scan_chosen(unsigned long node, 
const char *uname,
 
/* Retrieve command line */
p = of_get_flat_dt_prop(node, "bootargs", );
+
+#ifdef CONFIG_GENERIC_CMDLINE
+   /*
+* The builtin command line will be added here, or it can override
+* with the DT bootargs.
+*/
+   cmdline_add_builtin(data,
+   (l > 0 ? p : NULL), /* This is sanity checking */
+   COMMAND_LINE_SIZE);
+#else
if (p != NULL && l > 0)
strlcpy(data, p, min(l, COMMAND_LINE_SIZE));
 
@@ -1070,6 +1081,7 @@ int __init early_init_dt_scan_chosen(unsigned long node, 
const char *uname,
strlcpy(data, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
 #endif
 #endif /* CONFIG_CMDLINE */
+#endif /* CONFIG_GENERIC_CMDLINE */
 
pr_debug("Command line is: %s\n", (char *)data);
 
-- 
2.25.1



[PATCH v2 2/7] CMDLINE: drivers: of: ifdef out cmdline section

2021-03-08 Thread Daniel Walker
It looks like there's some seepage of cmdline stuff into
the generic device tree code. This conflicts with the
generic cmdline implementation so I remove it in the case
when that's enabled.

Cc: xe-linux-exter...@cisco.com
Signed-off-by: Ruslan Ruslichenko 
Signed-off-by: Daniel Walker 
---
 drivers/of/fdt.c | 12 
 1 file changed, 12 insertions(+)

diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index feb0f2d67fc5..e25240d84632 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -25,6 +25,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include   /* for COMMAND_LINE_SIZE */
 #include 
@@ -1050,6 +1051,16 @@ int __init early_init_dt_scan_chosen(unsigned long node, 
const char *uname,
 
/* Retrieve command line */
p = of_get_flat_dt_prop(node, "bootargs", );
+
+#ifdef CONFIG_GENERIC_CMDLINE
+   /*
+* The builtin command line will be added here, or it can override
+* with the DT bootargs.
+*/
+   cmdline_add_builtin(data,
+   (l > 0 ? p : NULL), /* This is sanity checking */
+   COMMAND_LINE_SIZE);
+#else
if (p != NULL && l > 0)
strlcpy(data, p, min(l, COMMAND_LINE_SIZE));
 
@@ -1070,6 +1081,7 @@ int __init early_init_dt_scan_chosen(unsigned long node, 
const char *uname,
strlcpy(data, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
 #endif
 #endif /* CONFIG_CMDLINE */
+#endif /* CONFIG_GENERIC_CMDLINE */
 
pr_debug("Command line is: %s\n", (char *)data);
 
-- 
2.25.1



[PATCH v2 1/7] CMDLINE: add generic builtin command line

2021-03-08 Thread Daniel Walker
This code allows architectures to use a generic builtin command line.
The state of the builtin command line options across architecture is
diverse. On x86 and mips they have pretty much the same code and the
code prepends the builtin command line onto the boot loader provided
one. On powerpc there is only a builtin override and nothing else.

The code in this commit unifies the code into a generic
header file under the CONFIG_GENERIC_CMDLINE option. When this
option is enabled the architecture can call the cmdline_add_builtin()
to add the builtin command line.

Cc: xe-linux-exter...@cisco.com
Signed-off-by: Ruslan Bilovol 
Signed-off-by: Daniel Walker 
---
 include/linux/cmdline.h | 89 +
 init/Kconfig| 68 +++
 2 files changed, 157 insertions(+)
 create mode 100644 include/linux/cmdline.h

diff --git a/include/linux/cmdline.h b/include/linux/cmdline.h
new file mode 100644
index ..00929b6e49e6
--- /dev/null
+++ b/include/linux/cmdline.h
@@ -0,0 +1,89 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_CMDLINE_H
+#define _LINUX_CMDLINE_H
+
+/*
+ *
+ * Copyright (C) 2006,2021. Cisco Systems, Inc.
+ *
+ * Generic Append/Prepend cmdline support.
+ */
+
+#if defined(CONFIG_GENERIC_CMDLINE) && defined(CONFIG_CMDLINE_BOOL)
+
+#ifndef CONFIG_CMDLINE_OVERRIDE
+#define GENERIC_CMDLINE_NEED_STRLCAT
+/*
+ * This function will append or prepend a builtin command line to the command
+ * line provided by the bootloader. Kconfig options can be used to alter
+ * the behavior of this builtin command line.
+ * @dest: The destination of the final appended/prepended string
+ * @src: The starting string or NULL if there isn't one.
+ * @tmp: temporary space used for prepending
+ * @length: the maximum length of the strings above.
+ * @cmdline_strlcpy: point to a compatible strlcpy
+ * @cmdline_strlcat: point to a compatible strlcat
+ */
+static inline void
+__cmdline_add_builtin(char *dest, const char *src, char *tmp, unsigned long 
length,
+   size_t (*cmdline_strlcpy)(char *dest, const char *src, size_t 
size),
+   size_t (*cmdline_strlcat)(char *dest, const char *src, size_t 
count))
+{
+   if (src != dest && src != NULL) {
+   cmdline_strlcpy(dest, " ", length);
+   cmdline_strlcat(dest, src, length);
+   }
+
+   if (sizeof(CONFIG_CMDLINE_APPEND) > 1)
+   cmdline_strlcat(dest, " " CONFIG_CMDLINE_APPEND, length);
+
+   if (sizeof(CONFIG_CMDLINE_PREPEND) > 1) {
+   cmdline_strlcpy(tmp, CONFIG_CMDLINE_PREPEND " ", length);
+   cmdline_strlcat(tmp, dest, length);
+   cmdline_strlcpy(dest, tmp, length);
+   }
+}
+
+#define cmdline_add_builtin_custom(dest, src, length, label, cmdline_strlcpy, 
cmdline_strlcat) \
+{  
\
+   if (sizeof(CONFIG_CMDLINE_PREPEND) > 1) {   
\
+   static label char cmdline_tmp_space[length];
\
+   __cmdline_add_builtin(dest, src, cmdline_tmp_space, length, 
cmdline_strlcpy, cmdline_strlcat);  \
+   } else if (sizeof(CONFIG_CMDLINE_APPEND) > 1) { 
\
+   __cmdline_add_builtin(dest, src, NULL, length, cmdline_strlcpy, 
cmdline_strlcat);   \
+   }   
\
+}
+#define cmdline_add_builtin(dest, src, length) \
+   cmdline_add_builtin_custom(dest, src, length, __initdata, strlcpy, 
strlcat)
+
+#else /* CONFIG_CMDLINE_OVERRIDE */
+
+static inline void
+__cmdline_add_builtin_custom(char *dest, const char *src, unsigned long length,
+   size_t (*cmdline_strlcpy)(char *dest, const char *src, size_t 
size))
+{
+   cmdline_strlcpy(dest, CONFIG_CMDLINE_PREPEND " " CONFIG_CMDLINE_APPEND, 
length);
+}
+#define cmdline_add_builtin_custom(dest, src, length, label, cmdline_strlcpy, 
cmdline_strlcat) \
+   __cmdline_add_builtin_custom(dest, src, length, cmdline_strlcpy)
+#define cmdline_add_builtin(dest, src, length) \
+   __cmdline_add_builtin_custom(dest, src, length, strlcpy)
+#endif /* !CONFIG_CMDLINE_OVERRIDE */
+
+#else /* !CONFIG_GENERIC_CMDLINE || !CONFIG_CMDLINE_BOOL */
+
+static inline void
+__cmdline_add_builtin_custom(char *dest, const char *src, unsigned long length,
+   size_t (*cmdline_strlcpy)(char *dest, const char *src, size_t 
size))
+{
+   if (src != NULL)
+   cmdline_strlcpy(dest, src, length);
+}
+#define cmdline_add_builtin_custom(dest, src, length, label, cmdline_strlcpy, 
cmdline_strlcat) \
+   __cmdline_add_builtin_custom(d

[PATCH v2 0/7] Generic Command Line changes

2021-03-08 Thread Daniel Walker
This fixed some problem identified in my last release. I made updates
based on comments from Christophe Leroy.

I added scripted updates to the defconfig file for mips and powerpc.
This is required in order to maintain the status quo for those platforms
which used the prior builtin command line system.

These were tested on all effected architectures.

Daniel Walker (7):
  CMDLINE: add generic builtin command line
  CMDLINE: drivers: of: ifdef out cmdline section
  powerpc: convert config files to generic cmdline
  CMDLINE: powerpc: convert to generic builtin command line
  mips: convert config files to generic cmdline
  CMDLINE: mips: convert to generic builtin command line
  CMDLINE: x86: convert to generic builtin command line

 arch/mips/Kconfig |  4 +-
 arch/mips/Kconfig.debug   | 44 -
 arch/mips/configs/ar7_defconfig   |  9 +-
 arch/mips/configs/bcm47xx_defconfig   |  8 +-
 arch/mips/configs/bcm63xx_defconfig   | 15 ++--
 arch/mips/configs/bmips_be_defconfig  | 11 +--
 arch/mips/configs/bmips_stb_defconfig | 11 +--
 arch/mips/configs/capcella_defconfig  | 11 +--
 arch/mips/configs/ci20_defconfig  | 10 +--
 arch/mips/configs/cu1000-neo_defconfig| 10 +--
 arch/mips/configs/cu1830-neo_defconfig| 10 +--
 arch/mips/configs/e55_defconfig   |  4 +-
 arch/mips/configs/generic_defconfig   |  6 +-
 arch/mips/configs/gpr_defconfig   | 18 +---
 arch/mips/configs/loongson3_defconfig | 13 +--
 arch/mips/configs/mpc30x_defconfig|  7 +-
 arch/mips/configs/tb0219_defconfig|  7 +-
 arch/mips/configs/tb0226_defconfig|  7 +-
 arch/mips/configs/tb0287_defconfig|  7 +-
 arch/mips/configs/workpad_defconfig   | 11 +--
 arch/mips/kernel/setup.c  | 36 +---
 arch/powerpc/Kconfig  | 37 +---
 arch/powerpc/configs/44x/fsp2_defconfig   | 33 ---
 arch/powerpc/configs/44x/iss476-smp_defconfig | 25 +++---
 arch/powerpc/configs/44x/warp_defconfig   | 17 ++--
 arch/powerpc/configs/holly_defconfig  | 13 +--
 arch/powerpc/configs/mvme5100_defconfig   | 23 ++---
 arch/powerpc/configs/skiroot_defconfig| 12 ++-
 arch/powerpc/configs/storcenter_defconfig | 18 ++--
 arch/powerpc/kernel/prom.c|  1 +
 arch/powerpc/kernel/prom_init.c   | 35 +---
 arch/x86/Kconfig  | 44 +
 arch/x86/kernel/setup.c   | 18 +---
 drivers/firmware/efi/libstub/x86-stub.c   |  2 +-
 drivers/of/fdt.c  | 12 +++
 include/linux/cmdline.h   | 89 +++
 init/Kconfig  | 68 ++
 37 files changed, 321 insertions(+), 385 deletions(-)
 create mode 100644 include/linux/cmdline.h

-- 
2.25.1



Re: [PATCH 2/5] CMDLINE: drivers: of: ifdef out cmdline section

2021-03-04 Thread Daniel Walker
On Thu, Mar 04, 2021 at 08:09:52AM +0100, Christophe Leroy wrote:
> 
> 
> Le 04/03/2021 à 05:47, Daniel Walker a écrit :
> > It looks like there's some seepage of cmdline stuff into
> > the generic device tree code. This conflicts with the
> > generic cmdline implementation so I remove it in the case
> > when that's enabled.
> > 
> > Cc: xe-linux-exter...@cisco.com
> > Signed-off-by: Ruslan Ruslichenko 
> > Signed-off-by: Daniel Walker 
> > ---
> >   drivers/of/fdt.c | 12 
> >   1 file changed, 12 insertions(+)
> > 
> > diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
> > index feb0f2d67fc5..cfe4f8d3c9f5 100644
> > --- a/drivers/of/fdt.c
> > +++ b/drivers/of/fdt.c
> > @@ -25,6 +25,7 @@
> >   #include 
> >   #include 
> >   #include 
> > +#include 
> >   #include   /* for COMMAND_LINE_SIZE */
> >   #include 
> > @@ -1048,8 +1049,18 @@ int __init early_init_dt_scan_chosen(unsigned long 
> > node, const char *uname,
> > early_init_dt_check_for_initrd(node);
> > +#ifdef CONFIG_GENERIC_CMDLINE
> > /* Retrieve command line */
> > p = of_get_flat_dt_prop(node, "bootargs", );
> > +
> > +   /*
> > +* The builtin command line will be added here, or it can override
> > +* with the DT bootargs.
> > +*/
> > +   cmdline_add_builtin(data,
> > +   ((p != NULL && l > 0) ? p : NULL), /* This is 
> > sanity checking */
> 
> Can we do more simple ? If p is NULL, p is already NULL, so (l > 0 ? p : 
> NULL) should be enough.


I believe Rob gave me this line. Maybe he can comment on it.

Daniel


Re: [PATCH 1/5] CMDLINE: add generic builtin command line

2021-03-04 Thread Daniel Walker
On Thu, Mar 04, 2021 at 08:00:49AM +0100, Christophe Leroy wrote:
> 
> 
> Le 04/03/2021 à 05:47, Daniel Walker a écrit :
> > This code allows architectures to use a generic builtin command line.
> > The state of the builtin command line options across architecture is
> > diverse. On x86 and mips they have pretty much the same code and the
> > code prepends the builtin command line onto the boot loader provided
> > one. On powerpc there is only a builtin override and nothing else.
> 
> This is not exact. powerpc has:
> CONFIG_FROM_BOOTLOADER
> CONFIG_EXTEND
> CONFIG_FORCE
 
I don't currently have ppc64 to test on, but CONFIG_FROM_BOOTLOADER should 
likely
stay, but the other two can come from the generic code.


> > 
> > The code in this commit unifies the code into a generic
> > header file under the CONFIG_GENERIC_CMDLINE option. When this
> > option is enabled the architecture can call the cmdline_add_builtin()
> > to add the builtin command line.
> > 
> > Cc: xe-linux-exter...@cisco.com
> > Signed-off-by: Ruslan Bilovol 
> > Signed-off-by: Daniel Walker 
> > ---
> >   include/linux/cmdline.h | 75 +
> >   init/Kconfig| 68 +
> >   2 files changed, 143 insertions(+)
> >   create mode 100644 include/linux/cmdline.h
> > 
> > diff --git a/include/linux/cmdline.h b/include/linux/cmdline.h
> > new file mode 100644
> > index ..f44011d1a9ee
> > --- /dev/null
> > +++ b/include/linux/cmdline.h
> > @@ -0,0 +1,75 @@
> 
> Missing the SPDX Licence Identifier
> 
> > +#ifndef _LINUX_CMDLINE_H
> > +#define _LINUX_CMDLINE_H
> > +
> > +/*
> > + *
> > + * Copyright (C) 2006,2021. Cisco Systems, Inc.
> > + *
> > + * Generic Append/Prepend cmdline support.
> > + */
> > +
> > +#if defined(CONFIG_GENERIC_CMDLINE) && defined(CONFIG_CMDLINE_BOOL)
> 
> I think it would be better if we can avoid the CONFIG_CMDLINE_BOOL.
> By making the CMDLINEs default to "" at all time, I think we can about that 
> BOOL.

Wouldn't it be annoying if you have to deleted all the characters from two text
boxes vs. just disabling a single option ? What if you leave a space
accidentally , woops.

> > +
> > +#ifndef CONFIG_CMDLINE_OVERRIDE
> > +/*
> > + * This function will append or prepend a builtin command line to the 
> > command
> 
> As far as I understand, it doesn't "append _or_ prepend" but it does "append 
> _and_ prepend"

I think the end results is accurately , no need to get pedantic.

> > + * line provided by the bootloader. Kconfig options can be used to alter
> > + * the behavior of this builtin command line.
> > + * @dest: The destination of the final appended/prepended string
> > + * @src: The starting string or NULL if there isn't one.
> > + * @tmp: temporary space used for prepending
> > + * @length: the maximum length of the strings above.
> 
> Missing some parameters here, but I think we should avoid those 'strlcpy'
> and 'strlcat', see later comment.
> 
> > + */
> > +static inline void
> > +__cmdline_add_builtin(char *dest, const char *src, char *tmp, unsigned 
> > long length,
> > +   size_t (*strlcpy)(char *dest, const char *src, size_t size),
> > +   size_t (*strlcat)(char *dest, const char *src, size_t count)
> 
> Don't use names that overide names of existing functions.
> 
> 'count' is __kernel_size_t not size_t
 
It's type checking all the parameters at compile time, it doesn't complain about
this that I've seen.


> > +   )
> > +{
> > +   if (src != dest && src != NULL) {
> > +   strlcpy(dest, " ", length);
> 
> Why do you need a space up front in that case ? Why not just copy the source 
> to the destination ?

There may not be a space between them, it doesn't cost anything to have one.

> > +   strlcat(dest, src, length);
> > +   }
> > +
> > +   if (sizeof(CONFIG_CMDLINE_APPEND) > 1)
> > +   strlcat(dest, " " CONFIG_CMDLINE_APPEND, length);
> > +
> > +   if (sizeof(CONFIG_CMDLINE_PREPEND) > 1) {
> > +   strlcpy(tmp, CONFIG_CMDLINE_PREPEND " ", length);
> > +   strlcat(tmp, dest, length);
> > +   strlcpy(dest, tmp, length);
> 
> Could we use memmove(), or implement strmove() and avoid the temporary buffer 
> at all ?

I don't really want to make drastic alteration like this, unless there is a
better reason for it. Most of this hasn't change insi

Re: [PATCH 2/5] CMDLINE: drivers: of: ifdef out cmdline section

2021-03-04 Thread Daniel Walker
On Thu, Mar 04, 2021 at 08:32:37AM -0600, Rob Herring wrote:
> On Wed, Mar 3, 2021 at 10:48 PM Daniel Walker  wrote:
> >
> > It looks like there's some seepage of cmdline stuff into
> > the generic device tree code. This conflicts with the
> > generic cmdline implementation so I remove it in the case
> > when that's enabled.
> >
> > Cc: xe-linux-exter...@cisco.com
> > Signed-off-by: Ruslan Ruslichenko 
> > Signed-off-by: Daniel Walker 
> > ---
> >  drivers/of/fdt.c | 12 
> >  1 file changed, 12 insertions(+)
> >
> > diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
> > index feb0f2d67fc5..cfe4f8d3c9f5 100644
> > --- a/drivers/of/fdt.c
> > +++ b/drivers/of/fdt.c
> > @@ -25,6 +25,7 @@
> >  #include 
> >  #include 
> >  #include 
> > +#include 
> >
> >  #include   /* for COMMAND_LINE_SIZE */
> >  #include 
> > @@ -1048,8 +1049,18 @@ int __init early_init_dt_scan_chosen(unsigned long 
> > node, const char *uname,
> >
> > early_init_dt_check_for_initrd(node);
> >
> > +#ifdef CONFIG_GENERIC_CMDLINE
> 
> What I like about Christophe's version is it removes the old DT
> implementation. Who's going to convert the rest of the DT based
> arches? That's arm, arm64, hexagon, microblaze, nios2, openrisc,
> riscv, sh, and xtensa. Either separate the common code from the config
> like Christophe's version or these all need converting. Though it's
> fine to hash out patch 1 with a couple of arches first.
 
I'm limited in what I can test, so I can't know for sure that I have something
which works on those architectures. Even powerpc 64 is part of this series but
I can't really test it at this time. Also Cisco's needs out strip the
implementation of extend or override.

I have un-tested conversions for arm32, arm64, c6x, microblaze, nios2, and
openrisc. These could go into -next and we can see who complains. The
implementation on these architectures isn't all uniform.

> > /* Retrieve command line */
> > p = of_get_flat_dt_prop(node, "bootargs", );
> 
> This needs to be outside the ifdef.

Ok ..

Daniel


[PATCH 5/5] CMDLINE: x86: convert to generic builtin command line

2021-03-03 Thread Daniel Walker
This updates the x86 code to use the CONFIG_GENERIC_CMDLINE
option.

Cc: xe-linux-exter...@cisco.com
Signed-off-by: Ruslan Ruslichenko 
Signed-off-by: Ruslan Bilovol 
Signed-off-by: Daniel Walker 
---
 arch/x86/Kconfig| 44 +
 arch/x86/kernel/setup.c | 18 ++
 drivers/firmware/efi/libstub/x86-stub.c |  2 +-
 3 files changed, 4 insertions(+), 60 deletions(-)

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 21f851179ff0..3950f9bf9855 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -115,6 +115,7 @@ config X86
select EDAC_SUPPORT
select GENERIC_CLOCKEVENTS_BROADCASTif X86_64 || (X86_32 && 
X86_LOCAL_APIC)
select GENERIC_CLOCKEVENTS_MIN_ADJUST
+   select GENERIC_CMDLINE
select GENERIC_CMOS_UPDATE
select GENERIC_CPU_AUTOPROBE
select GENERIC_CPU_VULNERABILITIES
@@ -2368,49 +2369,6 @@ choice
 
 endchoice
 
-config CMDLINE_BOOL
-   bool "Built-in kernel command line"
-   help
- Allow for specifying boot arguments to the kernel at
- build time.  On some systems (e.g. embedded ones), it is
- necessary or convenient to provide some or all of the
- kernel boot arguments with the kernel itself (that is,
- to not rely on the boot loader to provide them.)
-
- To compile command line arguments into the kernel,
- set this option to 'Y', then fill in the
- boot arguments in CONFIG_CMDLINE.
-
- Systems with fully functional boot loaders (i.e. non-embedded)
- should leave this option set to 'N'.
-
-config CMDLINE
-   string "Built-in kernel command string"
-   depends on CMDLINE_BOOL
-   default ""
-   help
- Enter arguments here that should be compiled into the kernel
- image and used at boot time.  If the boot loader provides a
- command line at boot time, it is appended to this string to
- form the full kernel command line, when the system boots.
-
- However, you can use the CONFIG_CMDLINE_OVERRIDE option to
- change this behavior.
-
- In most cases, the command line (whether built-in or provided
- by the boot loader) should specify the device for the root
- file system.
-
-config CMDLINE_OVERRIDE
-   bool "Built-in command line overrides boot loader arguments"
-   depends on CMDLINE_BOOL && CMDLINE != ""
-   help
- Set this option to 'Y' to have the kernel ignore the boot loader
- command line, and use ONLY the built-in command line.
-
- This is used to work around broken boot loaders.  This should
- be set to 'N' under normal conditions.
-
 config MODIFY_LDT_SYSCALL
bool "Enable the LDT (local descriptor table)" if EXPERT
default y
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index 740f3bdb3f61..e748c3e5c1ae 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -48,6 +48,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /*
  * max_low_pfn_mapped: highest directly mapped pfn < 4 GB
@@ -162,9 +163,6 @@ unsigned long saved_video_mode;
 #define RAMDISK_LOAD_FLAG  0x4000
 
 static char __initdata command_line[COMMAND_LINE_SIZE];
-#ifdef CONFIG_CMDLINE_BOOL
-static char __initdata builtin_cmdline[COMMAND_LINE_SIZE] = CONFIG_CMDLINE;
-#endif
 
 #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
 struct edd edd;
@@ -884,19 +882,7 @@ void __init setup_arch(char **cmdline_p)
bss_resource.start = __pa_symbol(__bss_start);
bss_resource.end = __pa_symbol(__bss_stop)-1;
 
-#ifdef CONFIG_CMDLINE_BOOL
-#ifdef CONFIG_CMDLINE_OVERRIDE
-   strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
-#else
-   if (builtin_cmdline[0]) {
-   /* append boot loader cmdline to builtin */
-   strlcat(builtin_cmdline, " ", COMMAND_LINE_SIZE);
-   strlcat(builtin_cmdline, boot_command_line, COMMAND_LINE_SIZE);
-   strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
-   }
-#endif
-#endif
-
+   cmdline_add_builtin(boot_command_line, NULL, COMMAND_LINE_SIZE);
strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
*cmdline_p = command_line;
 
diff --git a/drivers/firmware/efi/libstub/x86-stub.c 
b/drivers/firmware/efi/libstub/x86-stub.c
index f14c4ff5839f..9538c9d4a0bc 100644
--- a/drivers/firmware/efi/libstub/x86-stub.c
+++ b/drivers/firmware/efi/libstub/x86-stub.c
@@ -736,7 +736,7 @@ unsigned long efi_main(efi_handle_t handle,
}
 
 #ifdef CONFIG_CMDLINE_BOOL
-   status = efi_parse_options(CONFIG_CMDLINE);
+   status = efi_parse_options(CONFIG_CMDLINE_PREPEND " " 
CONFIG_CMDLINE_APPEND);
if (status != EFI_SUCCESS) {
efi_err("Failed to parse options\n");
goto fail;
-- 
2.25.1



[PATCH 2/5] CMDLINE: drivers: of: ifdef out cmdline section

2021-03-03 Thread Daniel Walker
It looks like there's some seepage of cmdline stuff into
the generic device tree code. This conflicts with the
generic cmdline implementation so I remove it in the case
when that's enabled.

Cc: xe-linux-exter...@cisco.com
Signed-off-by: Ruslan Ruslichenko 
Signed-off-by: Daniel Walker 
---
 drivers/of/fdt.c | 12 
 1 file changed, 12 insertions(+)

diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index feb0f2d67fc5..cfe4f8d3c9f5 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -25,6 +25,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include   /* for COMMAND_LINE_SIZE */
 #include 
@@ -1048,8 +1049,18 @@ int __init early_init_dt_scan_chosen(unsigned long node, 
const char *uname,
 
early_init_dt_check_for_initrd(node);
 
+#ifdef CONFIG_GENERIC_CMDLINE
/* Retrieve command line */
p = of_get_flat_dt_prop(node, "bootargs", );
+
+   /*
+* The builtin command line will be added here, or it can override
+* with the DT bootargs.
+*/
+   cmdline_add_builtin(data,
+   ((p != NULL && l > 0) ? p : NULL), /* This is 
sanity checking */
+   COMMAND_LINE_SIZE);
+#else
if (p != NULL && l > 0)
strlcpy(data, p, min(l, COMMAND_LINE_SIZE));
 
@@ -1070,6 +1081,7 @@ int __init early_init_dt_scan_chosen(unsigned long node, 
const char *uname,
strlcpy(data, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
 #endif
 #endif /* CONFIG_CMDLINE */
+#endif /* CONFIG_GENERIC_CMDLINE */
 
pr_debug("Command line is: %s\n", (char *)data);
 
-- 
2.25.1



[PATCH 4/5] CMDLINE: mips: convert to generic builtin command line

2021-03-03 Thread Daniel Walker
This updates the mips code to use the CONFIG_GENERIC_CMDLINE
option.

This deletes the option for MIPS_CMDLINE_BUILTIN_EXTEND
and replaces the functionality with generic code.

Cc: xe-linux-exter...@cisco.com
Signed-off-by: Ruslan Ruslichenko 
Signed-off-by: Ruslan Bilovol 
Signed-off-by: Daniel Walker 
---
 arch/mips/Kconfig|  4 +---
 arch/mips/Kconfig.debug  | 44 
 arch/mips/kernel/setup.c | 37 +
 3 files changed, 6 insertions(+), 79 deletions(-)

diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index 0a17bedf4f0d..7c07b3bca9fc 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -23,6 +23,7 @@ config MIPS
select CPU_NO_EFFICIENT_FFS if (TARGET_ISA_REV < 1)
select CPU_PM if CPU_IDLE
select GENERIC_ATOMIC64 if !64BIT
+   select GENERIC_CMDLINE
select GENERIC_CMOS_UPDATE
select GENERIC_CPU_AUTOPROBE
select GENERIC_GETTIMEOFDAY
@@ -3171,9 +3172,6 @@ choice
config MIPS_CMDLINE_FROM_BOOTLOADER
bool "Bootloader kernel arguments if available"
 
-   config MIPS_CMDLINE_BUILTIN_EXTEND
-   depends on CMDLINE_BOOL
-   bool "Extend builtin kernel arguments with bootloader arguments"
 endchoice
 
 endmenu
diff --git a/arch/mips/Kconfig.debug b/arch/mips/Kconfig.debug
index 7a8d94cdd493..b5a099c74eb6 100644
--- a/arch/mips/Kconfig.debug
+++ b/arch/mips/Kconfig.debug
@@ -30,50 +30,6 @@ config EARLY_PRINTK_8250
 config USE_GENERIC_EARLY_PRINTK_8250
bool
 
-config CMDLINE_BOOL
-   bool "Built-in kernel command line"
-   help
- For most systems, it is firmware or second stage bootloader that
- by default specifies the kernel command line options.  However,
- it might be necessary or advantageous to either override the
- default kernel command line or add a few extra options to it.
- For such cases, this option allows you to hardcode your own
- command line options directly into the kernel.  For that, you
- should choose 'Y' here, and fill in the extra boot arguments
- in CONFIG_CMDLINE.
-
- The built-in options will be concatenated to the default command
- line if CMDLINE_OVERRIDE is set to 'N'. Otherwise, the default
- command line will be ignored and replaced by the built-in string.
-
- Most MIPS systems will normally expect 'N' here and rely upon
- the command line from the firmware or the second-stage bootloader.
-
-config CMDLINE
-   string "Default kernel command string"
-   depends on CMDLINE_BOOL
-   help
- On some platforms, there is currently no way for the boot loader to
- pass arguments to the kernel.  For these platforms, and for the cases
- when you want to add some extra options to the command line or ignore
- the default command line, you can supply some command-line options at
- build time by entering them here.  In other cases you can specify
- kernel args so that you don't have to set them up in board prom
- initialization routines.
-
- For more information, see the CMDLINE_BOOL and CMDLINE_OVERRIDE
- options.
-
-config CMDLINE_OVERRIDE
-   bool "Built-in command line overrides firmware arguments"
-   depends on CMDLINE_BOOL
-   help
- By setting this option to 'Y' you will have your kernel ignore
- command line arguments from firmware or second stage bootloader.
- Instead, the built-in command line will be used exclusively.
-
- Normally, you will choose 'N' here.
-
 config SB1XXX_CORELIS
bool "Corelis Debugger"
depends on SIBYTE_SB1xxx_SOC
diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c
index 7e1f8e277437..b7e9c1c9 100644
--- a/arch/mips/kernel/setup.c
+++ b/arch/mips/kernel/setup.c
@@ -23,6 +23,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -67,12 +68,6 @@ EXPORT_SYMBOL(mips_machtype);
 static char __initdata command_line[COMMAND_LINE_SIZE];
 char __initdata arcs_cmdline[COMMAND_LINE_SIZE];
 
-#ifdef CONFIG_CMDLINE_BOOL
-static const char builtin_cmdline[] __initconst = CONFIG_CMDLINE;
-#else
-static const char builtin_cmdline[] __initconst = "";
-#endif
-
 /*
  * mips_io_port_base is the begin of the address space to which x86 style
  * I/O ports are mapped.
@@ -546,27 +541,7 @@ static void __init bootcmdline_init(void)
 {
bool dt_bootargs = false;
 
-   /*
-* If CMDLINE_OVERRIDE is enabled then initializing the command line is
-* trivial - we simply use the built-in command line unconditionally &
-* unmodified.
-*/
-   if (IS_ENABLED(CONFIG_CMDLINE_OVERRIDE)) {
-   strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
-   return;
- 

[PATCH 1/5] CMDLINE: add generic builtin command line

2021-03-03 Thread Daniel Walker
This code allows architectures to use a generic builtin command line.
The state of the builtin command line options across architecture is
diverse. On x86 and mips they have pretty much the same code and the
code prepends the builtin command line onto the boot loader provided
one. On powerpc there is only a builtin override and nothing else.

The code in this commit unifies the code into a generic
header file under the CONFIG_GENERIC_CMDLINE option. When this
option is enabled the architecture can call the cmdline_add_builtin()
to add the builtin command line.

Cc: xe-linux-exter...@cisco.com
Signed-off-by: Ruslan Bilovol 
Signed-off-by: Daniel Walker 
---
 include/linux/cmdline.h | 75 +
 init/Kconfig| 68 +
 2 files changed, 143 insertions(+)
 create mode 100644 include/linux/cmdline.h

diff --git a/include/linux/cmdline.h b/include/linux/cmdline.h
new file mode 100644
index ..f44011d1a9ee
--- /dev/null
+++ b/include/linux/cmdline.h
@@ -0,0 +1,75 @@
+#ifndef _LINUX_CMDLINE_H
+#define _LINUX_CMDLINE_H
+
+/*
+ *
+ * Copyright (C) 2006,2021. Cisco Systems, Inc.
+ *
+ * Generic Append/Prepend cmdline support.
+ */
+
+#if defined(CONFIG_GENERIC_CMDLINE) && defined(CONFIG_CMDLINE_BOOL)
+
+#ifndef CONFIG_CMDLINE_OVERRIDE
+/*
+ * This function will append or prepend a builtin command line to the command
+ * line provided by the bootloader. Kconfig options can be used to alter
+ * the behavior of this builtin command line.
+ * @dest: The destination of the final appended/prepended string
+ * @src: The starting string or NULL if there isn't one.
+ * @tmp: temporary space used for prepending
+ * @length: the maximum length of the strings above.
+ */
+static inline void
+__cmdline_add_builtin(char *dest, const char *src, char *tmp, unsigned long 
length,
+   size_t (*strlcpy)(char *dest, const char *src, size_t size),
+   size_t (*strlcat)(char *dest, const char *src, size_t count)
+   )
+{
+   if (src != dest && src != NULL) {
+   strlcpy(dest, " ", length);
+   strlcat(dest, src, length);
+   }
+
+   if (sizeof(CONFIG_CMDLINE_APPEND) > 1)
+   strlcat(dest, " " CONFIG_CMDLINE_APPEND, length);
+
+   if (sizeof(CONFIG_CMDLINE_PREPEND) > 1) {
+   strlcpy(tmp, CONFIG_CMDLINE_PREPEND " ", length);
+   strlcat(tmp, dest, length);
+   strlcpy(dest, tmp, length);
+   }
+}
+
+#define cmdline_add_builtin_custom(dest, src, length, label, strlcpy, strlcat) 
\
+{  
\
+   if (sizeof(CONFIG_CMDLINE_PREPEND) > 1) {   
\
+   static label char cmdline_tmp_space[length];
\
+   __cmdline_add_builtin(dest, src, cmdline_tmp_space, length, 
strlcpy, strlcat);  \
+   } else if (sizeof(CONFIG_CMDLINE_APPEND) > 1) { 
\
+   __cmdline_add_builtin(dest, src, NULL, length, strlcpy, 
strlcat);   \
+   }   
\
+}
+#define cmdline_add_builtin(dest, src, length)\
+   cmdline_add_builtin_custom(dest, src, length, __initdata, , 
)
+#else
+#define cmdline_add_builtin(dest, src, length)\
+{ \
+   strlcpy(dest, CONFIG_CMDLINE_PREPEND " " CONFIG_CMDLINE_APPEND,\
+   length);   \
+}
+#endif /* !CONFIG_CMDLINE_OVERRIDE */
+
+#else
+#define cmdline_add_builtin_custom(dest, src, length, label, strlcpy, strlcat) 
{ \
+   if (src != NULL)
 \
+   strlcpy(dest, src, length); 
 \
+}
+
+#define cmdline_add_builtin(dest, src, length) {   
\
+   cmdline_add_builtin_custom(dest, src, length, strlcpy, strlcat);
\
+}
+#endif /* CONFIG_GENERIC_CMDLINE */
+
+
+#endif /* _LINUX_CMDLINE_H */
diff --git a/init/Kconfig b/init/Kconfig
index 29ad68325028..28363ab07cd4 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -2032,6 +2032,74 @@ config PROFILING
 config TRACEPOINTS
bool
 
+config GENERIC_CMDLINE
+   bool
+
+if GENERIC_CMDLINE
+
+config CMDLINE_BOOL
+   bool "Built-in kernel command line"
+   help
+ Allow for specifying boot arguments to the kernel at
+ build time.  On some systems (e.g. embedded ones), it is
+ necessary or convenient to provide some or all of the
+ kernel boot arguments with the ke

[PATCH 3/5] CMDLINE: powerpc: convert to generic builtin command line

2021-03-03 Thread Daniel Walker
This updates the powerpc code to use the CONFIG_GENERIC_CMDLINE
option.

Cc: xe-linux-exter...@cisco.com
Signed-off-by: Ruslan Ruslichenko 
Signed-off-by: Ruslan Bilovol 
Signed-off-by: Daniel Walker 
---
 arch/powerpc/Kconfig| 37 +
 arch/powerpc/kernel/prom.c  |  1 +
 arch/powerpc/kernel/prom_init.c | 31 +++
 3 files changed, 20 insertions(+), 49 deletions(-)

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 107bb4319e0e..276b06d5c961 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -167,6 +167,7 @@ config PPC
select EDAC_SUPPORT
select GENERIC_ATOMIC64 if PPC32
select GENERIC_CLOCKEVENTS_BROADCASTif SMP
+   select GENERIC_CMDLINE
select GENERIC_CMOS_UPDATE
select GENERIC_CPU_AUTOPROBE
select GENERIC_CPU_VULNERABILITIES  if PPC_BARRIER_NOSPEC
@@ -906,42 +907,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
-   string "Initial kernel command string"
-   default ""
-   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.
-
-choice
-   prompt "Kernel command line type" if CMDLINE != ""
-   default CMDLINE_FROM_BOOTLOADER
-
-config CMDLINE_FROM_BOOTLOADER
-   bool "Use bootloader kernel arguments if available"
-   help
- Uses the command-line options passed by the boot loader. If
- the boot loader doesn't provide any, the default kernel command
- string provided in CMDLINE will be used.
-
-config CMDLINE_EXTEND
-   bool "Extend bootloader kernel arguments"
-   help
- The command-line arguments provided by the boot loader will be
- appended to the default kernel command string.
-
-config CMDLINE_FORCE
-   bool "Always use the default kernel command string"
-   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.
-
-endchoice
-
 config EXTRA_TARGETS
string "Additional default image types"
help
diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c
index ae3c41730367..96d0a01be1b4 100644
--- a/arch/powerpc/kernel/prom.c
+++ b/arch/powerpc/kernel/prom.c
@@ -27,6 +27,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/powerpc/kernel/prom_init.c b/arch/powerpc/kernel/prom_init.c
index e9d4eb6144e1..d752be688b62 100644
--- a/arch/powerpc/kernel/prom_init.c
+++ b/arch/powerpc/kernel/prom_init.c
@@ -27,6 +27,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -242,15 +243,6 @@ static int __init prom_strcmp(const char *cs, const char 
*ct)
return 0;
 }
 
-static char __init *prom_strcpy(char *dest, const char *src)
-{
-   char *tmp = dest;
-
-   while ((*dest++ = *src++) != '\0')
-   /* nothing */;
-   return tmp;
-}
-
 static int __init prom_strncmp(const char *cs, const char *ct, size_t count)
 {
unsigned char c1, c2;
@@ -276,6 +268,19 @@ static size_t __init prom_strlen(const char *s)
return sc - s;
 }
 
+static size_t __init prom_strlcpy(char *dest, const char *src, size_t size)
+{
+   size_t ret = prom_strlen(src);
+
+   if (size) {
+   size_t len = (ret >= size) ? size - 1 : ret;
+   memcpy(dest, src, len);
+   dest[len] = '\0';
+   }
+   return ret;
+}
+
+
 static int __init prom_memcmp(const void *cs, const void *ct, size_t count)
 {
const unsigned char *su1, *su2;
@@ -778,9 +783,9 @@ static void __init early_cmdline_parse(void)
if (!IS_ENABLED(CONFIG_CMDLINE_FORCE) && (long)prom.chosen > 0)
l = prom_getprop(prom.chosen, "bootargs", p, 
COMMAND_LINE_SIZE-1);
 
-   if (IS_ENABLED(CONFIG_CMDLINE_EXTEND) || l <= 0 || p[0] == '\0')
-   prom_strlcat(prom_cmd_line, " " CONFIG_CMDLINE,
-sizeof(prom_cmd_line));
+   if (l <= 0 || p[0] == '\0') /* dbl check */
+   cmdline_add_builtin_custom(prom_cmd_line, NULL, 
sizeof(prom_cmd_line),
+   __prombss, _strlcpy, 
_strlcat);
 
prom_printf("command line: %s\n", prom_cmd_line);
 
@@ -2706,7 +2711,7 @@ static void __init flatten_device_tree(void)
 
 

Re: [PATCH v2 0/7] Improve boot command line handling

2021-03-03 Thread Daniel Walker
On Wed, Mar 03, 2021 at 07:07:45PM +0100, Christophe Leroy wrote:
> 
> 
> Le 03/03/2021 à 18:39, Daniel Walker a écrit :
> > On Tue, Mar 02, 2021 at 08:01:01PM -0600, Rob Herring wrote:
> > > +Will D
> > > 
> > > On Tue, Mar 2, 2021 at 11:36 AM Daniel Walker  wrote:
> > > > 
> > > > On Tue, Mar 02, 2021 at 05:25:16PM +, Christophe Leroy wrote:
> > > > > The purpose of this series is to improve and enhance the
> > > > > handling of kernel boot arguments.
> > > > > 
> > > > > It is first focussed on powerpc but also extends the capability
> > > > > for other arches.
> > > > > 
> > > > > This is based on suggestion from Daniel Walker 
> > > > > 
> > > > 
> > > > 
> > > > I don't see a point in your changes at this time. My changes are much 
> > > > more
> > > > mature, and you changes don't really make improvements.
> > > 
> > > Not really a helpful comment. What we merge here will be from whomever
> > > is persistent and timely in their efforts. But please, work together
> > > on a common solution.
> > > 
> > > This one meets my requirements of moving the kconfig and code out of
> > > the arches, supports prepend/append, and is up to date.
> > 
> > 
> > Maintainers are capable of merging whatever they want to merge. However, I
> > wouldn't make hasty choices. The changes I've been submitting have been 
> > deployed
> > on millions of router instances and are more feature rich.
> > 
> > I believe I worked with you on this change, or something like it,
> > 
> > https://lkml.org/lkml/2019/3/19/970
> > 
> > I don't think Christophe has even addressed this.
> 
> I thing I have, see 
> https://patchwork.ozlabs.org/project/linuxppc-dev/patch/3b4291271ce4af4941a771e5af5cbba3c8fa1b2a.1614705851.git.christophe.le...@csgroup.eu/
> 
> If you see something missing in that patch, can you tell me.
 
Ok, must have missed that one.


> > I've converted many
> > architectures, and Cisco uses my changes on at least 4 different
> > architecture. With products deployed and tested.
> 
> As far as we know, only powerpc was converted in the last series you
> submitted, see
> https://patchwork.ozlabs.org/project/linuxppc-dev/list/?series=98106=*


Me and others submitted my changes many times, and other architectures have 
been included. The patch
you submitted I've submitted similar at Rob's request years ago.

Here a fuller submissions some time ago,

https://lore.kernel.org/patchwork/cover/992768/

You've only been involved in prior powerpc only submissions.

Daniel


Re: [PATCH v2 0/7] Improve boot command line handling

2021-03-03 Thread Daniel Walker
On Tue, Mar 02, 2021 at 08:01:01PM -0600, Rob Herring wrote:
> +Will D
> 
> On Tue, Mar 2, 2021 at 11:36 AM Daniel Walker  wrote:
> >
> > On Tue, Mar 02, 2021 at 05:25:16PM +, Christophe Leroy wrote:
> > > The purpose of this series is to improve and enhance the
> > > handling of kernel boot arguments.
> > >
> > > It is first focussed on powerpc but also extends the capability
> > > for other arches.
> > >
> > > This is based on suggestion from Daniel Walker 
> > >
> >
> >
> > I don't see a point in your changes at this time. My changes are much more
> > mature, and you changes don't really make improvements.
> 
> Not really a helpful comment. What we merge here will be from whomever
> is persistent and timely in their efforts. But please, work together
> on a common solution.
> 
> This one meets my requirements of moving the kconfig and code out of
> the arches, supports prepend/append, and is up to date.


Maintainers are capable of merging whatever they want to merge. However, I
wouldn't make hasty choices. The changes I've been submitting have been deployed
on millions of router instances and are more feature rich.

I believe I worked with you on this change, or something like it,

https://lkml.org/lkml/2019/3/19/970

I don't think Christophe has even addressed this. I've converted many
architectures, and Cisco uses my changes on at least 4 different
architecture. With products deployed and tested.

I will resubmit my changes as soon as I can.

Daniel


Re: [PATCH v2 0/7] Improve boot command line handling

2021-03-02 Thread Daniel Walker
On Tue, Mar 02, 2021 at 05:25:16PM +, Christophe Leroy wrote:
> The purpose of this series is to improve and enhance the
> handling of kernel boot arguments.
> 
> It is first focussed on powerpc but also extends the capability
> for other arches.
> 
> This is based on suggestion from Daniel Walker 
> 


I don't see a point in your changes at this time. My changes are much more
mature, and you changes don't really make improvements.

Daniel


Re: [PATCH 0/2] Fix CMDLINE_EXTEND handling for FDT "bootargs"

2021-03-02 Thread Daniel Walker
On Mon, Mar 01, 2021 at 11:26:14AM -0600, Rob Herring wrote:
> +PPC folks and Daniel W
> 
> On Mon, Mar 1, 2021 at 8:42 AM Will Deacon  wrote:
> >
> > On Mon, Mar 01, 2021 at 08:19:32AM -0600, Rob Herring wrote:
> > > On Thu, Feb 25, 2021 at 6:59 AM Will Deacon  wrote:
> > > > We recently [1] enabled support for CMDLINE_EXTEND on arm64, however
> > > > when I started looking at replacing Android's out-of-tree 
> > > > implementation [2]
> > >
> > > Did anyone go read the common, reworked version of all this I
> > > referenced that supports prepend and append. Here it is again[1].
> > > Maybe I should have been more assertive there and said 'extend' is
> > > ambiguous.
> >
> > I tried reading that, but (a) most of the series is not in the mailing list
> > archives and (b) the patch that _is_ doesn't touch CMDLINE_EXTEND at all.
> > Right now the code in mainline does the opposite of what it's documented to
> > do.
> 
> Actually, there is a newer version I found:
> 
> https://lore.kernel.org/linuxppc-dev/1551469472-53043-1-git-send-email-danie...@cisco.com/
> https://lore.kernel.org/linuxppc-dev/1551469472-53043-2-git-send-email-danie...@cisco.com/
> https://lore.kernel.org/linuxppc-dev/1551469472-53043-3-git-send-email-danie...@cisco.com/
> 
> (Once again, there's some weird threading going on)
> 

I'm happy to work with anyone to resubmit the changes. We currently use the
changes in Cisco, and we have used them for many years.

I was planning to update and resubmit since someone has recently inquired about
why it wasn't upstream.

Daniel


Re: [PATCH 1/4] add generic builtin command line

2021-02-16 Thread Daniel Walker
On Mon, Feb 15, 2021 at 11:32:01AM -0800, Daniel Gimpelevich wrote:
> On Thu, 2019-03-21 at 15:15 -0700, Andrew Morton wrote:
> > On Thu, 21 Mar 2019 08:13:08 -0700 Daniel Walker  wrote:
> > > On Wed, Mar 20, 2019 at 08:14:33PM -0700, Andrew Morton wrote:
> > > > The patches (or some version of them) are already in linux-next,
> > > > which messes me up.  I'll disable them for now.
> > >  
> > > Those are from my tree, but I remove them when you picked up the series. 
> > > The
> > > next linux-next should not have them.
> > 
> > Yup, thanks, all looks good now.
> 
> This patchset is currently neither in mainline nor in -next. May I ask
> what happened to it? Thanks.
> 

It was dropped silently by Andrew at some point. I wasn't watching -next closely
to know when. I have no idea why he dropped it.

We still use this series extensively in Cisco, and have extended it beyond this
current series.

We can re-submit.

Daniel


Re: [PATCH 2/2] audit: show (grand)parents information of an audit context

2021-02-03 Thread Daniel Walker (danielwa)
On Tue, Feb 02, 2021 at 04:44:47PM -0500, Paul Moore wrote:
> On Tue, Feb 2, 2021 at 4:29 PM Daniel Walker  wrote:
> > From: Phil Zhang 
> >
> > To ease the root cause analysis of SELinux AVCs, this new feature
> > traverses task structs to iteratively find all parent processes
> > starting with the denied process and ending at the kernel. Meanwhile,
> > it prints out the command lines and subject contexts of those parents.
> >
> > This provides developers a clear view of how processes were spawned
> > and where transitions happened, without the need to reproduce the
> > issue and manually audit interesting events.
> >
> > Example on bash over ssh:
> > $ runcon -u system_u -r system_r -t polaris_hm_t ls
> > ...
> > type=PARENT msg=audit(1610548241.033:255): 
> > subj=root:unconfined_r:unconfined_t:s0-s0:c0.c1023  cmdline="-bash"
> > type=PARENT msg=audit(1610548241.033:255): 
> > subj=system_u:system_r:sshd_t:s0-s0:c0.c1023cmdline="sshd: 
> > root@pts/0"
> > type=PARENT msg=audit(1610548241.033:255): 
> > subj=system_u:system_r:sshd_t:s0-s0:c0.c1023
> > cmdline="/tmp/sw/rp/0/0/rp_security/mount/usr/sbin/sshd
> > type=PARENT msg=audit(1610548241.033:255): 
> > subj=system_u:system_r:init_t:s0cmdline="/init"
> >     type=PARENT msg=audit(1610548241.033:255): 
> > subj=system_u:system_r:kernel_t:s0
> > ...
> >
> > Cc: xe-linux-exter...@cisco.com
> > Signed-off-by: Phil Zhang 
> > Signed-off-by: Daniel Walker 
> > ---
> >  include/uapi/linux/audit.h |  5 ++-
> >  init/Kconfig   |  7 +
> >  kernel/audit.c |  3 +-
> >  kernel/auditsc.c   | 64 ++
> >  4 files changed, 77 insertions(+), 2 deletions(-)
> 
> This is just for development/testing of SELinux policy, right?  It
> seems like this is better done in userspace to me through a
> combination of policy analysis and just understanding of how your
> system is put together.
 
That's why the patch was create to better understand the system.

> If you really need this information in the audit log for some
> production use, it seems like you could audit the various
> fork()/exec() syscalls to get an understanding of the various process
> (sub)trees on the system.  It would require a bit of work to sift
> through the audit log and reconstruct the events that led to a process
> being started, and generating the AVC you are interested in debugging,
> but folks who live The Audit Life supposedly do this sort of thing a
> lot (this sort of thing being tracing a process/session).

We have a very complex and constantly changing system, and we use shell scripts
some of the time. If a shell script triggers an AVC it will typically show the
tool called instead of the shell script which triggered calling the tool.

We do have audit enabled in production systems, and I think we collect these
logs in case of issues on the production system. Phil is better to address this.

We're willing to try alternatives like what you suggested above.

Daniel


Re: [PATCH 1/2] audit: show user land backtrace as part of audit context messages

2021-02-02 Thread Daniel Walker (danielwa)
On Tue, Feb 02, 2021 at 04:35:42PM -0500, Paul Moore wrote:
> On Tue, Feb 2, 2021 at 4:29 PM Daniel Walker  wrote:
> > From: Victor Kamensky 
> >
> > To efficiently find out where SELinux AVC denial is comming from
> > take backtrace of user land process and display it as type=UBACKTRACE
> > message that comes as audit context for SELinux AVC and other audit
> > messages ...
> 
> Have you tried the new perf tracepoint for SELinux AVC decisions that
> trigger an audit event?  It's a new feature for v5.10 and looks to
> accomplish most of what you are looking for with this patch.
> 
> * https://www.paul-moore.com/blog/d/2020/12/linux_v510.html

We haven't tried it, but I can look into it. We're not using v5.10 extensively
yet.

Daniel

[PATCH 2/2] audit: show (grand)parents information of an audit context

2021-02-02 Thread Daniel Walker
From: Phil Zhang 

To ease the root cause analysis of SELinux AVCs, this new feature
traverses task structs to iteratively find all parent processes
starting with the denied process and ending at the kernel. Meanwhile,
it prints out the command lines and subject contexts of those parents.

This provides developers a clear view of how processes were spawned
and where transitions happened, without the need to reproduce the
issue and manually audit interesting events.

Example on bash over ssh:
$ runcon -u system_u -r system_r -t polaris_hm_t ls
...
type=PARENT msg=audit(1610548241.033:255): 
subj=root:unconfined_r:unconfined_t:s0-s0:c0.c1023  cmdline="-bash"
type=PARENT msg=audit(1610548241.033:255): 
subj=system_u:system_r:sshd_t:s0-s0:c0.c1023cmdline="sshd: root@pts/0"
type=PARENT msg=audit(1610548241.033:255): 
subj=system_u:system_r:sshd_t:s0-s0:c0.c1023
cmdline="/tmp/sw/rp/0/0/rp_security/mount/usr/sbin/sshd
type=PARENT msg=audit(1610548241.033:255): subj=system_u:system_r:init_t:s0 
   cmdline="/init"
type=PARENT msg=audit(1610548241.033:255): 
subj=system_u:system_r:kernel_t:s0
...

Cc: xe-linux-exter...@cisco.com
Signed-off-by: Phil Zhang 
Signed-off-by: Daniel Walker 
---
 include/uapi/linux/audit.h |  5 ++-
 init/Kconfig   |  7 +
 kernel/audit.c |  3 +-
 kernel/auditsc.c   | 64 ++
 4 files changed, 77 insertions(+), 2 deletions(-)

diff --git a/include/uapi/linux/audit.h b/include/uapi/linux/audit.h
index 7bea44b1c028..8f1a2880b198 100644
--- a/include/uapi/linux/audit.h
+++ b/include/uapi/linux/audit.h
@@ -119,6 +119,7 @@
 #define AUDIT_BPF  1334/* BPF subsystem */
 #define AUDIT_EVENT_LISTENER   1335/* Task joined multicast read socket */
 #define AUDIT_UBACKTRACE   1336/* User land backtrace */
+#define AUDIT_PARENT   1340/* Process Parent emit event */
 
 #define AUDIT_AVC  1400/* SE Linux avc denial or grant */
 #define AUDIT_SELINUX_ERR  1401/* Internal SE Linux Errors */
@@ -485,7 +486,9 @@ struct audit_features {
 #define AUDIT_FEATURE_ONLY_UNSET_LOGINUID  0
 #define AUDIT_FEATURE_LOGINUID_IMMUTABLE   1
 #define AUDIT_FEATURE_UBACKTRACE_CONTEXT   2
-#define AUDIT_LAST_FEATURE AUDIT_FEATURE_UBACKTRACE_CONTEXT
+#define AUDIT_FEATURE_LIST_PARENTS 3
+#define AUDIT_LAST_FEATURE AUDIT_FEATURE_LIST_PARENTS
+
 
 #define audit_feature_valid(x) ((x) >= 0 && (x) <= AUDIT_LAST_FEATURE)
 #define AUDIT_FEATURE_TO_MASK(x)   (1 << ((x) & 31)) /* mask for __u32 */
diff --git a/init/Kconfig b/init/Kconfig
index 4327a8afb1f9..2dbc1c2aa833 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -446,6 +446,13 @@ config AUDIT_USER_BACKTRACE_SIZE
 depends on AUDIT_USER_BACKTRACE
 default 40
 
+config AUDIT_LIST_PARENTS
+   bool "Displaying parent processes in audit context messages"
+   def_bool n
+   depends on AUDITSYSCALL
+   help
+ Capture contexts and cmdlines of parent processes when auditing 
syscalls
+
 source "kernel/irq/Kconfig"
 source "kernel/time/Kconfig"
 source "kernel/Kconfig.preempt"
diff --git a/kernel/audit.c b/kernel/audit.c
index 4608cddb4bb9..834adc462f47 100644
--- a/kernel/audit.c
+++ b/kernel/audit.c
@@ -165,10 +165,11 @@ static struct audit_features af = {.vers = 
AUDIT_FEATURE_VERSION,
   .features = 0,
   .lock = 0,};
 
-static char *audit_feature_names[3] = {
+static char *audit_feature_names[4] = {
"only_unset_loginuid",
"loginuid_immutable",
"ubacktrace_context",
+   "list_parents",
 };
 
 /**
diff --git a/kernel/auditsc.c b/kernel/auditsc.c
index d048b01345b8..c27e9f928bf1 100644
--- a/kernel/auditsc.c
+++ b/kernel/auditsc.c
@@ -96,6 +96,10 @@
 /* number of audit rules */
 int audit_n_rules;
 
+/* max length of per audit entry and max number of entries */
+#define MAX_PARENT_AUDIT_LEN 256
+#define MAX_PARENT_ENTRY_CNT 16
+
 /* determines whether we collect data for signals sent */
 int audit_signals;
 
@@ -1472,6 +1476,61 @@ static void audit_log_proctitle(void)
audit_log_end(ab);
 }
 
+static void audit_log_parents(void)
+{
+   int res, len, item_cnt;
+   u32 sid;
+   char *buf;
+   char *ctx = NULL;
+   struct audit_context *context = audit_context();
+   struct audit_buffer *ab;
+   struct task_struct *task_iter;
+
+   if (!context || context->dummy)
+   return;
+
+   buf = kmalloc(MAX_PARENT_AUDIT_LEN, GFP_KERNEL);
+   if (!buf)
+   return;
+
+   rcu_read_lock();
+   task_iter = rcu_dereference(current->real_parent);
+   for (item_cnt = 0

[PATCH 1/2] audit: show user land backtrace as part of audit context messages

2021-02-02 Thread Daniel Walker
From: Victor Kamensky 

To efficiently find out where SELinux AVC denial is comming from
take backtrace of user land process and display it as type=UBACKTRACE
message that comes as audit context for SELinux AVC and other audit
messages.

By default UBACKTRACE context messages are off. Needs to be enabled
through audit AUDIT_FEATURE_UBACKTRACE_CONTEXT feature.

Context UBACKTRACE message example:
type=UBACKTRACE msg=audit(1574205625.557:30): 
backtrace=libc-2.30.so+0xc99ab:dmesg.util-linux+0x1483:libc-2.30.so+0x1e35:dmesg.util-linux+0x1e5a

I.e because of ASLR instead of absolute user land addresses, name
of executable or library captured and followed by offset from text
segment vma. To decode backtrace entry: find executable or library
symbol file, find its text segment vma and add offset to it; run
'addr2line -f -e symbol_file resulting_address'.

Note feature depends on PERF_EVENTS, from perf subsystem it uses
perf_callchain_user function on architectures where it is implemented.
And it has the same capturing restriction as 'perf -g': user land code
must be compiled with -fno-omit-frame-pointer option, otherwise kernel
is not capable walk user land stack frames.

Cc: xe-linux-exter...@cisco.com
Signed-off-by: Victor Kamensky 
Signed-off-by: Ruslan Bilovol 
Signed-off-by: Daniel Walker 
---
 include/uapi/linux/audit.h |  6 ++-
 init/Kconfig   | 13 ++
 kernel/audit.c |  3 +-
 kernel/auditsc.c   | 93 ++
 4 files changed, 112 insertions(+), 3 deletions(-)

diff --git a/include/uapi/linux/audit.h b/include/uapi/linux/audit.h
index cd2d8279a5e4..7bea44b1c028 100644
--- a/include/uapi/linux/audit.h
+++ b/include/uapi/linux/audit.h
@@ -118,6 +118,7 @@
 #define AUDIT_TIME_ADJNTPVAL   1333/* NTP value adjustment */
 #define AUDIT_BPF  1334/* BPF subsystem */
 #define AUDIT_EVENT_LISTENER   1335/* Task joined multicast read socket */
+#define AUDIT_UBACKTRACE   1336/* User land backtrace */
 
 #define AUDIT_AVC  1400/* SE Linux avc denial or grant */
 #define AUDIT_SELINUX_ERR  1401/* Internal SE Linux Errors */
@@ -474,7 +475,7 @@ struct audit_status {
 };
 
 struct audit_features {
-#define AUDIT_FEATURE_VERSION  1
+#define AUDIT_FEATURE_VERSION  2
__u32   vers;
__u32   mask;   /* which bits we are dealing with */
__u32   features;   /* which feature to enable/disable */
@@ -483,7 +484,8 @@ struct audit_features {
 
 #define AUDIT_FEATURE_ONLY_UNSET_LOGINUID  0
 #define AUDIT_FEATURE_LOGINUID_IMMUTABLE   1
-#define AUDIT_LAST_FEATURE AUDIT_FEATURE_LOGINUID_IMMUTABLE
+#define AUDIT_FEATURE_UBACKTRACE_CONTEXT   2
+#define AUDIT_LAST_FEATURE AUDIT_FEATURE_UBACKTRACE_CONTEXT
 
 #define audit_feature_valid(x) ((x) >= 0 && (x) <= AUDIT_LAST_FEATURE)
 #define AUDIT_FEATURE_TO_MASK(x)   (1 << ((x) & 31)) /* mask for __u32 */
diff --git a/init/Kconfig b/init/Kconfig
index b77c60f8b963..4327a8afb1f9 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -433,6 +433,19 @@ config AUDITSYSCALL
depends on AUDIT && HAVE_ARCH_AUDITSYSCALL
select FSNOTIFY
 
+config AUDIT_USER_BACKTRACE
+bool "Enable user land backtrace in audit context messages"
+def_bool n
+depends on AUDITSYSCALL && PERF_EVENTS
+help
+  Enable UBACKTRACE audit context messages, capturing backtrace of
+  user land process causing the message.
+
+config AUDIT_USER_BACKTRACE_SIZE
+int "Maximum size of user land backtrace entries captured in UBACKTACE"
+depends on AUDIT_USER_BACKTRACE
+default 40
+
 source "kernel/irq/Kconfig"
 source "kernel/time/Kconfig"
 source "kernel/Kconfig.preempt"
diff --git a/kernel/audit.c b/kernel/audit.c
index 1ffc2e059027..4608cddb4bb9 100644
--- a/kernel/audit.c
+++ b/kernel/audit.c
@@ -165,9 +165,10 @@ static struct audit_features af = {.vers = 
AUDIT_FEATURE_VERSION,
   .features = 0,
   .lock = 0,};
 
-static char *audit_feature_names[2] = {
+static char *audit_feature_names[3] = {
"only_unset_loginuid",
"loginuid_immutable",
+   "ubacktrace_context",
 };
 
 /**
diff --git a/kernel/auditsc.c b/kernel/auditsc.c
index ce8c9e2279ba..d048b01345b8 100644
--- a/kernel/auditsc.c
+++ b/kernel/auditsc.c
@@ -67,6 +67,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -74,6 +75,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -1470,6 +1472,92 @@ static void audit_log_proctitle(void)
audit_log_end(ab);
 }
 
+#ifdef CONFIG_AUDIT_USER_BACKTRACE
+static void audit_log_print_backtrace(struct audit_buffer *ab,
+ struct task_struct *tsk,

Re: [PATCH 1/2] arm64: boot: dts: add new dts for hellcat & petra

2021-01-25 Thread Daniel Walker (danielwa)
On Mon, Jan 25, 2021 at 08:52:01AM +0100, Michal Simek wrote:
> > 
> >>
> >> Long time ago we said that we are not going to push any PL related
> >> configurations. It means all below can't be merged.
> >> And there are also coding style issues.
> > 
> > You'll need to explain this more. It's likely this was added at the 
> > suggestion of
> > Xilinx. If it can't be upstreamed what should we replace it with ?
> 
> No idea who gave you this suggestion from Xilinx.
 
Just an FYI , I didn't write this dts or work on it's original development so I
can't name names.

> I had similar thread with Michael Walle about supporting Ebang board.
> PL depends on your custom design and can change quite quickly that's
> there is no good/bad configuration. That's why all of them can be valid
> and kernel is not the right location to store thousands of
> configurations (likely in overlay form). That's why only fixed
> configurations for PS are added to kernel.
> And I prefer if there is any good reason behind why these platforms
> should be added.

I'm not sure what your talking about above .. Are you suggesting the changes in
my DTS will change quickly ? They have been the same for years , we don't plan
to change them. This DTS is not a prototype it's a released Cisco product.

If I did delete this "PL configuration" where would you expect it to re-appear ?
Typically things which aren't upstreamable are transformed into something else,
it's rare that something is just removed and has no transformation.

Daniel

Re: [PATCH 1/2] arm64: boot: dts: add new dts for hellcat & petra

2021-01-22 Thread Daniel Walker (danielwa)
On Fri, Jan 22, 2021 at 09:48:53AM +0100, Michal Simek wrote:
> Hi Daniel,
> 
> On 1/22/21 12:12 AM, Daniel Walker wrote:
> > Add Petra and Hellcat dts file. These platforms are based on
> > the Xilinx Zynqmp platform.
> > 
> > Signed-off-by: Daniel Walker 
> > Cc: xe-linux-exter...@cisco.com
> > ---
> >  arch/arm64/boot/dts/xilinx/Makefile   |   2 +
> >  .../boot/dts/xilinx/zynqmp-petra-hellcat.dts  | 856 ++
> >  arch/arm64/boot/dts/xilinx/zynqmp-petra.dts   | 847 +
> >  3 files changed, 1705 insertions(+)
> >  create mode 100644 arch/arm64/boot/dts/xilinx/zynqmp-petra-hellcat.dts
> >  create mode 100644 arch/arm64/boot/dts/xilinx/zynqmp-petra.dts
> 
> First of all I can't see 2/2.
 
It wasn't being submitted to you. But here it is if you care to look at it.

https://lkml.org/lkml/2021/1/21/1468

> 
> Long time ago we said that we are not going to push any PL related
> configurations. It means all below can't be merged.
> And there are also coding style issues.

You'll need to explain this more. It's likely this was added at the suggestion 
of
Xilinx. If it can't be upstreamed what should we replace it with ?

I will review your other comments and re-submit.

Daniel

Re: [PATCH 2/2] spidev: Add cisco device compatible

2021-01-22 Thread Daniel Walker (danielwa)
On Fri, Jan 22, 2021 at 01:26:16PM +, Mark Brown wrote:
> On Thu, Jan 21, 2021 at 03:12:36PM -0800, Daniel Walker wrote:
> > Add compatible string for Cisco device present on the Cisco Petra
> > platform.
> 
> I'm missing patch 1 of this series, what's the story with dependencies?


The other commit is the usage of this change in a new DTS file,

Here is the link,

https://lkml.org/lkml/2021/1/21/1469

Daniel

[PATCH 1/2] arm64: boot: dts: add new dts for hellcat & petra

2021-01-21 Thread Daniel Walker
Add Petra and Hellcat dts file. These platforms are based on
the Xilinx Zynqmp platform.

Signed-off-by: Daniel Walker 
Cc: xe-linux-exter...@cisco.com
---
 arch/arm64/boot/dts/xilinx/Makefile   |   2 +
 .../boot/dts/xilinx/zynqmp-petra-hellcat.dts  | 856 ++
 arch/arm64/boot/dts/xilinx/zynqmp-petra.dts   | 847 +
 3 files changed, 1705 insertions(+)
 create mode 100644 arch/arm64/boot/dts/xilinx/zynqmp-petra-hellcat.dts
 create mode 100644 arch/arm64/boot/dts/xilinx/zynqmp-petra.dts

diff --git a/arch/arm64/boot/dts/xilinx/Makefile 
b/arch/arm64/boot/dts/xilinx/Makefile
index 60f5443f3ef4..d9eacb3c60e5 100644
--- a/arch/arm64/boot/dts/xilinx/Makefile
+++ b/arch/arm64/boot/dts/xilinx/Makefile
@@ -15,3 +15,5 @@ dtb-$(CONFIG_ARCH_ZYNQMP) += zynqmp-zcu102-rev1.0.dtb
 dtb-$(CONFIG_ARCH_ZYNQMP) += zynqmp-zcu104-revA.dtb
 dtb-$(CONFIG_ARCH_ZYNQMP) += zynqmp-zcu106-revA.dtb
 dtb-$(CONFIG_ARCH_ZYNQMP) += zynqmp-zcu111-revA.dtb
+dtb-$(CONFIG_ARCH_ZYNQMP) += zynqmp-petra.dts
+dtb-$(CONFIG_ARCH_ZYNQMP) += zynqmp-petra-hellcat.dts
diff --git a/arch/arm64/boot/dts/xilinx/zynqmp-petra-hellcat.dts 
b/arch/arm64/boot/dts/xilinx/zynqmp-petra-hellcat.dts
new file mode 100644
index ..87e23c1cac65
--- /dev/null
+++ b/arch/arm64/boot/dts/xilinx/zynqmp-petra-hellcat.dts
@@ -0,0 +1,856 @@
+/*
+ * dts file for Cisco Petra-Hellcat Switching IOT platform
+ *
+ * (C) Copyright 2016-2018, Cisco Systems, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ */
+
+/dts-v1/;
+
+#include "zynqmp.dtsi"
+#include "zynqmp-clk-ccf.dtsi"
+
+/*
+ * PL *
+ */
+
+/ {
+reserved-memory {
+#address-cells = <0x2>;
+#size-cells = <0x2>;
+ranges;
+
+rproc@3ed0 {
+no-map;
+reg = <0x0 0x3ed0 0x0 0x100>;
+};
+zynqmp_sha_reserved: buffer@0 {
+compatible = "shared-dma-pool";
+no-map;
+reg = <0x0 0x7800 0x0 0x0002>;
+};
+}; 
+
+sha384 {
+compatible = "xlnx,zynqmp-keccak-384";
+memory-region = <_sha_reserved>;
+};
+
+   amba_pl: amba_pl@0 {
+   #address-cells = <2>;
+   #size-cells = <2>;
+   compatible = "simple-bus";
+   ranges ;
+   design_1_i_axi_iic_BP: i2c@80104000 {
+   #address-cells = <1>;
+   #size-cells = <0>;
+clocks = <0x3 0x47>;
+   compatible = "xlnx,xps-iic-2.00.a";
+   interrupt-parent = <>;
+   interrupts = <0 93 4>;
+   reg = <0x0 0x80104000 0x0 0x1000>;
+   };
+   design_1_i_axi_iic_KM_PLT: i2c@80106000 {
+   #address-cells = <1>;
+   #size-cells = <0>;
+clocks = <0x3 0x47>;
+   compatible = "xlnx,xps-iic-2.00.a";
+   interrupt-parent = <>;
+   interrupts = <0 107 4>;
+   reg = <0x0 0x80106000 0x0 0x1000>;
+   };
+   design_1_i_axi_iic_LC1: i2c@8010 {
+   #address-cells = <1>;
+   #size-cells = <0>;
+clocks = <0x3 0x47>;
+   compatible = "xlnx,xps-iic-2.00.a";
+   interrupt-parent = <>;
+   interrupts = <0 89 4>;
+   reg = <0x0 0x8010 0x0 0x1000>;
+   };
+   design_1_i_axi_iic_LC2: i2c@80101000 {
+   #address-cells = <1>;
+   #size-cells = <0>;
+clocks = <0x3 0x47>;
+   compatible = "xlnx,xps-iic-2.00.a";
+   interrupt-parent = <>;
+   interrupts = <0 90 4>;
+   reg = <0x0 0x80101000 0x0 0x1000>;
+   };
+   design_1_i_axi_iic_LC3: i2c@80102000 {
+   #address-cells = <1>;
+   #size-cells = <0>;
+clocks = <0x3 0x47>;
+   compatible = "xlnx,xps-iic-2.00.a";
+   interrupt-parent = <>;
+   interrupts = <0 91 4>;
+   reg = <0x0 0x80102000 0x0 0x1000>;
+   };
+   design_1_i_axi_iic_PS: i2c@80103000 {
+  

[PATCH 2/2] spidev: Add cisco device compatible

2021-01-21 Thread Daniel Walker
Add compatible string for Cisco device present on the Cisco Petra
platform.

Signed-off-by: Daniel Walker 
Cc: xe-linux-exter...@cisco.com
---
 drivers/spi/spidev.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c
index 859910ec8d9f..8cb4d923aeaa 100644
--- a/drivers/spi/spidev.c
+++ b/drivers/spi/spidev.c
@@ -682,6 +682,7 @@ static const struct of_device_id spidev_dt_ids[] = {
{ .compatible = "lwn,bk4" },
{ .compatible = "dh,dhcom-board" },
{ .compatible = "menlo,m53cpld" },
+   { .compatible = "cisco,spi-petra" },
{},
 };
 MODULE_DEVICE_TABLE(of, spidev_dt_ids);
-- 
2.17.1



Re: linux-next: removal of the cisco tree

2020-06-16 Thread Daniel Walker
On Tue, Jun 16, 2020 at 03:00:09PM +1000, Stephen Rothwell wrote:
> Hi,
> 
> I have removed the cisco tree
> (https://github.com/daniel-walker/cisco-linux.git#for-next)
> from linux-next because it has not been updated in more than a year.
> If you would like it reinstated, please just reply and let me know.

I'll likely request it be added at a later date, but not at this time.

Thanks for notification.

Daniel


Re: [PATCH 2/2] mtd: spi-nor: intel-spi: fix forced writable option

2020-06-02 Thread Daniel Walker (danielwa)
On Thu, May 28, 2020 at 03:55:21PM +, Jinhua Wu (jinhwu) wrote:
> On 2020/5/28, 11:48 PM, "Jinhua Wu"  wrote:
> Hi Vignesh,
> BIOS just locked down parts of flash (such as, code region), others are still 
> writeable. Once the SPI locked down,it can't be override unless platfrom 
> reset 
> and set WPD (write protect disable) will fail, so ispi->writeable will always
> be 0, then the driver will always make the whole flash read only, even if we
> have set the parameter writable = 1. 
> Now the flash is totally not writeable, just part of it is read only. Why not 
>  making
> 'writeable' working when explicitly enabled?
> 
> >On 2020/5/28, 7:02 PM, "Vignesh Raghavendra"  wrote:
> >On 18/05/20 11:29 pm, Daniel Walker wrote:
> >> This option currently doesn't work as expected. If the BIOS has this
> >> flash as read-only there is no way to change this thru the driver.
> >> There is a parameter which allows the flash to become writable with the
> >> "writable" option to the module, but it does nothing if the BIOS has it
> >> set to read-only.
> >> 
> >> I would expect this option would make the flash writable regardless of
> >> the BIOS settings. This patch changes this option so the BIOS setting
> >> doesn't stop the writable option from enabling read write on the flash.
> >> 
> >
> >I am confused you say "If the BIOS has this flash as read-only there is
> >no way to change this thru the driver", so is it possible to override
> >BIOS setting? If yes, where is the code in the driver?
> >
> >What happens if BIOS is set to allow writes but writeable is set to 0?
> >
> >Also please send patch series as thread (2/2 in reply to 1/2). You can
> >use tool like git send-email
> >



Vignesh, do you still have concerns about this change ?


Daniel

[PATCH 1/2] mtd: spi-nor: create/Export parameter softwareseq for intel-spi driver to user

2020-05-18 Thread Daniel Walker
From: Bobby Liu 

How to use:
append softwareseq=1 while probe the driver.
example:
modprobe intel-spi writeable=1 softwareseq=1
it will let driver use software sequence to write register for opt=EN4B
by default it's 0 if not specified, driver will do usual HW cycle

Why this parameter is posted to user:
Intel PCH provides two groups of registers for SPI flash operation,
Hard Sequence registers and Software Sequence registers,
corresponding to intel_spi_hw_cycle() and intel_spi_sw_cycle()
respectively in driver code. But HW sequence register won't send EN4B
opcode to SPI flash. BIOS code use SW register to send EN4B.

On some Cisco routers, two 32M SPI flashes, which require 4-byte address mode 
enabled,
are physically connected to an FPGA, one flash is active and one is inactive.
When we do BIOS upgrade, we need switch to the inactive one,
but unfortunately, this one is still 3-byte address mode as default,
after we do real-time switch, we need reload SPI driver to send EN4B code to
enable 4-byte address mode.

Refering to our BIOS code, Software sequence register is processed
while sending EN4B opcode. So here we use sw_cycle in driver for EN4B as well.

Why I don't just easily use software sequence for all:
1.It will impact all flash operation, include flash W/R, high risk
2.The only SPI type I can use is INTEL_SPI_BXT according to datasheet,
  this will require using hw seq.
  I tried to specify other SPI type, it couldn't work with Intel PCH.
  If I force SW seq for all, during boot up, sw_cycle fails to read
  vendor ID.

In conclusion, I only use SW cycle for EN4B opcode to minimize impact.
It won't impact other users as well.

Why the default flash can work at 4-byte address mode:
BIOS sets 4-byte address mode for the current active SPI flash with SW seq 
registers.
So we don't need append softwareseq=1 for normal boot up script,
it will only be used in BIOS upgrade script.

Cc: xe-linux-exter...@cisco.com
Signed-off-by: Bobby Liu 
[ danielwa: edited the commit message a little. ]
Signed-off-by: Daniel Walker 
---
 drivers/mtd/spi-nor/controllers/intel-spi.c | 16 
 1 file changed, 16 insertions(+)

diff --git a/drivers/mtd/spi-nor/controllers/intel-spi.c 
b/drivers/mtd/spi-nor/controllers/intel-spi.c
index 61d2a0ad2131..e5a3d51a2e4d 100644
--- a/drivers/mtd/spi-nor/controllers/intel-spi.c
+++ b/drivers/mtd/spi-nor/controllers/intel-spi.c
@@ -163,6 +163,10 @@ static bool writeable;
 module_param(writeable, bool, 0);
 MODULE_PARM_DESC(writeable, "Enable write access to SPI flash chip 
(default=0)");
 
+static bool softwareseq;
+module_param(softwareseq, bool, 0);
+MODULE_PARM_DESC(softwareseq, "Use software sequence for register write 
(default=0)");
+
 static void intel_spi_dump_regs(struct intel_spi *ispi)
 {
u32 value;
@@ -619,6 +623,18 @@ static int intel_spi_write_reg(struct spi_nor *nor, u8 
opcode, const u8 *buf,
if (ret)
return ret;
 
+   /*
+* Intel Skylake will not send EN4B to SPI flash if we use HW sequence
+* Here export one interface "softwareseq" to OS,
+* let driver user decide if use SW sequence or not
+*/
+   if (opcode == SPINOR_OP_EN4B && softwareseq) {
+   dev_info(ispi->dev,
+   "Write register opcode is SPINOR_OP_EN4B, do SW cycle\n");
+   return intel_spi_sw_cycle(ispi, opcode, len,
+   OPTYPE_WRITE_NO_ADDR);
+   }
+
if (ispi->swseq_reg)
return intel_spi_sw_cycle(ispi, opcode, len,
  OPTYPE_WRITE_NO_ADDR);
-- 
2.17.1



[PATCH 2/2] mtd: spi-nor: intel-spi: fix forced writable option

2020-05-18 Thread Daniel Walker
This option currently doesn't work as expected. If the BIOS has this
flash as read-only there is no way to change this thru the driver.
There is a parameter which allows the flash to become writable with the
"writable" option to the module, but it does nothing if the BIOS has it
set to read-only.

I would expect this option would make the flash writable regardless of
the BIOS settings. This patch changes this option so the BIOS setting
doesn't stop the writable option from enabling read write on the flash.

Original patch by Jinhua Wu 

Cc: Jinhua Wu 
Cc: xe-linux-exter...@cisco.com
Signed-off-by: Daniel Walker 
---
 drivers/mtd/spi-nor/controllers/intel-spi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/spi-nor/controllers/intel-spi.c 
b/drivers/mtd/spi-nor/controllers/intel-spi.c
index e5a3d51a2e4d..68a5877bfc0b 100644
--- a/drivers/mtd/spi-nor/controllers/intel-spi.c
+++ b/drivers/mtd/spi-nor/controllers/intel-spi.c
@@ -954,7 +954,7 @@ struct intel_spi *intel_spi_probe(struct device *dev,
intel_spi_fill_partition(ispi, );
 
/* Prevent writes if not explicitly enabled */
-   if (!ispi->writeable || !writeable)
+   if (!ispi->writeable && !writeable)
ispi->nor.mtd.flags &= ~MTD_WRITEABLE;
 
ret = mtd_device_register(>nor.mtd, , 1);
-- 
2.17.1



Re: [RFC-PATCH] mtd: spi-nor: add conditional 4B opcodes

2020-05-08 Thread Daniel Walker (danielwa)
On Sat, May 09, 2020 at 12:37:35AM +0530, Pratyush Yadav wrote:
> Hi Daniel,
> 
> On 07/05/20 06:13PM, Daniel Walker (danielwa) wrote:
> > On Thu, May 07, 2020 at 11:33:46PM +0530, Pratyush Yadav wrote:
> > > On 07/05/20 09:20AM, Daniel Walker wrote:
> > > > Some chips have 4B opcodes, but there is no way to know if they have
> > > > them. This device tree option allows platform owners to force enable 4b
> > > > opcodes when they know their chips support it even when it can be
> > > > automatically identified.
> > > 
> > > Do you mean that two chips might have the same ID but one of them can 
> > > support 4B opcodes and the other can not? Is it possible to detect this 
> > > in a fixup hook? I think it would be better to do something like this in 
> > > a fixup hook instead of via device tree.
> >   
> > Yes. The chip I added the option for is an example of this, it's n25q256a. 
> > I'm not familiar with the
> > fixup hook mechanism, but I would assume you need some way to tell between 
> > the 4B
> > opcode chips and the non-4B opcode chips. For n25q256a, we have not found a 
> > way
> > to do that.
> 
> I'm assuming this patch is related to [0]. If all you want is to address 
> memory above 16M, why not switch to 4-byte addressing mode instead? 
> Taking a quick look at the datasheet tells me this can be done via the 
> "Enter 4-byte address mode" command (0xB7). Then just use the regular 
> read/program commands with 4-byte addresses. Does that work for you? Is 
> there any reason you _have_ to use dedicated 4B opcodes?

It might, I don't think we need anything beyond access to move than 16M. Your
proposal would be to have a hook which enters the 0xB7 command?

I guess the question would be do all the chips have this ability.

Daniel

Re: [RFC-PATCH] mtd: spi-nor: add conditional 4B opcodes

2020-05-07 Thread Daniel Walker (danielwa)





On Thu, May 07, 2020 at 11:33:46PM +0530, Pratyush Yadav wrote:
> On 07/05/20 09:20AM, Daniel Walker wrote:
> > Some chips have 4B opcodes, but there is no way to know if they have
> > them. This device tree option allows platform owners to force enable 4b
> > opcodes when they know their chips support it even when it can be
> > automatically identified.
> 
> Do you mean that two chips might have the same ID but one of them can 
> support 4B opcodes and the other can not? Is it possible to detect this 
> in a fixup hook? I think it would be better to do something like this in 
> a fixup hook instead of via device tree.
  
Yes. The chip I added the option for is an example of this, it's n25q256a. I'm 
not familiar with the
fixup hook mechanism, but I would assume you need some way to tell between the 
4B
opcode chips and the non-4B opcode chips. For n25q256a, we have not found a way
to do that.

Daniel

[RFC-PATCH] mtd: spi-nor: add conditional 4B opcodes

2020-05-07 Thread Daniel Walker
Some chips have 4B opcodes, but there is no way to know if they have
them. This device tree option allows platform owners to force enable 4b
opcodes when they know their chips support it even when it can be
automatically identified.

Cc: xe-linux-exter...@cisco.com
Signed-off-by: Daniel Walker 
---
 drivers/mtd/spi-nor/core.c  | 5 +
 drivers/mtd/spi-nor/core.h  | 5 +
 drivers/mtd/spi-nor/micron-st.c | 2 +-
 3 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index cc68ea84318e..2bd130687f4b 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -3134,6 +3134,11 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
if (info->flags & SPI_NOR_HAS_LOCK)
nor->flags |= SNOR_F_HAS_LOCK;
 
+   /* Add SPI_NOR_4B_OPCODES if force in the device tree */
+   if (info->flags & SPI_NOR_COND_4B_OPCODES &&
+   of_property_read_bool(np, "force-4b-opcodes"))
+   info->flags |= SPI_NOR_4B_OPCODES;
+
mtd->_write = spi_nor_write;
 
/* Init flash parameters based on flash_info struct and SFDP */
diff --git a/drivers/mtd/spi-nor/core.h b/drivers/mtd/spi-nor/core.h
index 6f2f6b27173f..49e17415d834 100644
--- a/drivers/mtd/spi-nor/core.h
+++ b/drivers/mtd/spi-nor/core.h
@@ -312,6 +312,11 @@ struct flash_info {
 * Must be used with SPI_NOR_4BIT_BP.
 */
 
+#define SPI_NOR_COND_4B_OPCODESBIT(19) /*
+* Same as SPI_NOR_4B_OPCODES, but
+* must also be force in the device
+* tree.
+*/
/* Part specific fixup hooks. */
const struct spi_nor_fixups *fixups;
 };
diff --git a/drivers/mtd/spi-nor/micron-st.c b/drivers/mtd/spi-nor/micron-st.c
index 6c034b9718e2..f827454eaa5f 100644
--- a/drivers/mtd/spi-nor/micron-st.c
+++ b/drivers/mtd/spi-nor/micron-st.c
@@ -37,7 +37,7 @@ static const struct flash_info st_parts[] = {
   SPI_NOR_QUAD_READ | SPI_NOR_4B_OPCODES) },
{ "n25q256a",INFO(0x20ba19, 0, 64 * 1024,  512, SECT_4K |
  USE_FSR | SPI_NOR_DUAL_READ |
- SPI_NOR_QUAD_READ) },
+ SPI_NOR_QUAD_READ | SPI_NOR_COND_4B_OPCODES) },
{ "mt25qu256a",  INFO6(0x20bb19, 0x104400, 64 * 1024,  512,
   SECT_4K | USE_FSR | SPI_NOR_DUAL_READ |
   SPI_NOR_QUAD_READ | SPI_NOR_4B_OPCODES) },
-- 
2.17.1



Re: [PATCH] igb: add parameter to ignore nvm checksum validation

2019-05-16 Thread Daniel Walker
On Thu, May 16, 2019 at 03:02:18PM -0700, Florian Fainelli wrote:
> On 5/16/19 12:55 PM, Nikunj Kela (nkela) wrote:
> > 
> > 
> > On 5/16/19, 12:35 PM, "Jeff Kirsher"  wrote:
> > 
> > On Wed, 2019-05-08 at 23:14 +, Nikunj Kela wrote:
> >>> Some of the broken NICs don't have EEPROM programmed correctly. It
> >>> results
> >>> in probe to fail. This change adds a module parameter that can be
> >>> used to
> >>> ignore nvm checksum validation.
> >>> 
> >>> Cc: xe-linux-exter...@cisco.com
> >>> Signed-off-by: Nikunj Kela 
> >>> ---
> >>>  drivers/net/ethernet/intel/igb/igb_main.c | 28
> >>> ++--
> >>>  1 file changed, 22 insertions(+), 6 deletions(-)
> > 
> > >NAK for two reasons.  First, module parameters are not desirable
> > >because their individual to one driver and a global solution should be
> > >found so that all networking device drivers can use the solution.  This
> > >will keep the interface to change/setup/modify networking drivers
> > >consistent for all drivers.
> > 
> > 
> > >Second and more importantly, if your NIC is broken, fix it.  Do not try
> > >and create a software workaround so that you can continue to use a
> > >broken NIC.  There are methods/tools available to properly reprogram
> > >the EEPROM on a NIC, which is the right solution for your issue.
> > 
> > I am proposing this as a debug parameter. Obviously, we need to fix EEPROM 
> > but this helps us continuing the development while manufacturing fixes NIC.
> 
> Then why even bother with sending this upstream?

It seems rather drastic to disable the entire driver because the checksum
doesn't match. It really should be a warning, even a big warning, to let people
know something is wrong, but disabling the whole driver doesn't make sense.

Daniel


[PATCH 3/3] powerpc: convert config files to generic cmdline

2019-03-01 Thread Daniel Walker
This is a scripted mass convert of the config files to use
the new generic cmdline. There is a bit of a trim effect here.
It would seems that some of the config haven't been trimmed in
a while.

The script used to convert is as follows,

if [[ -z "$1" || -z "$2" ]]; then
echo "Two arguments are needed."
exit 1
fi
mkdir $1
cp $2 $1/.config
sed -i 's/CONFIG_CMDLINE=/CONFIG_CMDLINE_PREPEND=/g' $1/.config
make ARCH=$1 O=$1 olddefconfig
make ARCH=$1 O=$1 savedefconfig
cp $1/defconfig $2
rm -Rf $1

Cc: xe-linux-exter...@cisco.com
Cc: Daniel Walker 
Signed-off-by: Daniel Walker 
---
 arch/powerpc/configs/44x/fsp2_defconfig   | 29 
 arch/powerpc/configs/44x/iss476-smp_defconfig | 24 +++---
 arch/powerpc/configs/44x/warp_defconfig   | 12 +++
 arch/powerpc/configs/holly_defconfig  | 12 +++
 arch/powerpc/configs/mvme5100_defconfig   | 25 +++---
 arch/powerpc/configs/skiroot_defconfig| 48 +--
 arch/powerpc/configs/storcenter_defconfig | 15 -
 7 files changed, 80 insertions(+), 85 deletions(-)

diff --git a/arch/powerpc/configs/44x/fsp2_defconfig 
b/arch/powerpc/configs/44x/fsp2_defconfig
index bae6b26bcfba..bafea495c9b8 100644
--- a/arch/powerpc/configs/44x/fsp2_defconfig
+++ b/arch/powerpc/configs/44x/fsp2_defconfig
@@ -1,8 +1,6 @@
-CONFIG_44x=y
 # CONFIG_SWAP is not set
 CONFIG_SYSVIPC=y
 # CONFIG_CROSS_MEMORY_ATTACH is not set
-# CONFIG_FHANDLE is not set
 CONFIG_NO_HZ=y
 CONFIG_HIGH_RES_TIMERS=y
 CONFIG_IKCONFIG=y
@@ -13,25 +11,26 @@ CONFIG_BLK_DEV_INITRD=y
 # CONFIG_RD_XZ is not set
 # CONFIG_RD_LZO is not set
 # CONFIG_RD_LZ4 is not set
+# CONFIG_FHANDLE is not set
 CONFIG_KALLSYMS_ALL=y
 CONFIG_BPF_SYSCALL=y
 CONFIG_EMBEDDED=y
 CONFIG_PROFILING=y
-CONFIG_OPROFILE=y
-CONFIG_MODULES=y
-CONFIG_MODULE_UNLOAD=y
-# CONFIG_BLK_DEV_BSG is not set
+CONFIG_CMDLINE_BOOL=y
+CONFIG_CMDLINE_PREPEND="ip=on rw"
+CONFIG_44x=y
 CONFIG_PPC_47x=y
 # CONFIG_EBONY is not set
 CONFIG_FSP2=y
 CONFIG_476FPE_ERR46=y
-CONFIG_SWIOTLB=y
 CONFIG_KEXEC=y
 CONFIG_CRASH_DUMP=y
-CONFIG_CMDLINE_BOOL=y
-CONFIG_CMDLINE="ip=on rw"
 # CONFIG_SUSPEND is not set
 # CONFIG_PCI is not set
+CONFIG_OPROFILE=y
+CONFIG_MODULES=y
+CONFIG_MODULE_UNLOAD=y
+# CONFIG_BLK_DEV_BSG is not set
 CONFIG_NET=y
 CONFIG_PACKET=y
 CONFIG_UNIX=y
@@ -112,6 +111,12 @@ CONFIG_NFS_V3_ACL=y
 CONFIG_NFS_V4=y
 CONFIG_ROOT_NFS=y
 CONFIG_NLS_DEFAULT="n"
+CONFIG_CRYPTO_CBC=y
+CONFIG_CRYPTO_ECB=y
+CONFIG_CRYPTO_PCBC=y
+CONFIG_CRYPTO_MD5=y
+CONFIG_CRYPTO_DES=y
+# CONFIG_CRYPTO_HW is not set
 CONFIG_XZ_DEC=y
 CONFIG_PRINTK_TIME=y
 CONFIG_MESSAGE_LOGLEVEL_DEFAULT=3
@@ -119,9 +124,3 @@ CONFIG_DYNAMIC_DEBUG=y
 CONFIG_DEBUG_INFO=y
 CONFIG_MAGIC_SYSRQ=y
 CONFIG_DETECT_HUNG_TASK=y
-CONFIG_CRYPTO_CBC=y
-CONFIG_CRYPTO_ECB=y
-CONFIG_CRYPTO_PCBC=y
-CONFIG_CRYPTO_MD5=y
-CONFIG_CRYPTO_DES=y
-# CONFIG_CRYPTO_HW is not set
diff --git a/arch/powerpc/configs/44x/iss476-smp_defconfig 
b/arch/powerpc/configs/44x/iss476-smp_defconfig
index d24bfa6ecd62..775b25178714 100644
--- a/arch/powerpc/configs/44x/iss476-smp_defconfig
+++ b/arch/powerpc/configs/44x/iss476-smp_defconfig
@@ -1,5 +1,3 @@
-CONFIG_44x=y
-CONFIG_SMP=y
 CONFIG_SYSVIPC=y
 CONFIG_POSIX_MQUEUE=y
 CONFIG_LOG_BUF_SHIFT=14
@@ -7,21 +5,23 @@ CONFIG_BLK_DEV_INITRD=y
 CONFIG_EXPERT=y
 CONFIG_KALLSYMS_ALL=y
 CONFIG_PROFILING=y
-CONFIG_OPROFILE=y
-CONFIG_MODULES=y
-CONFIG_MODULE_UNLOAD=y
-# CONFIG_BLK_DEV_BSG is not set
+CONFIG_CMDLINE_BOOL=y
+CONFIG_CMDLINE_PREPEND="root=/dev/issblk0"
+CONFIG_44x=y
+CONFIG_SMP=y
 CONFIG_PPC_47x=y
 # CONFIG_EBONY is not set
 CONFIG_ISS4xx=y
 CONFIG_HZ_100=y
 CONFIG_MATH_EMULATION=y
 CONFIG_IRQ_ALL_CPUS=y
-CONFIG_CMDLINE_BOOL=y
-CONFIG_CMDLINE="root=/dev/issblk0"
 # CONFIG_PCI is not set
 CONFIG_ADVANCED_OPTIONS=y
 CONFIG_DYNAMIC_MEMSTART=y
+CONFIG_OPROFILE=y
+CONFIG_MODULES=y
+CONFIG_MODULE_UNLOAD=y
+# CONFIG_BLK_DEV_BSG is not set
 CONFIG_NET=y
 CONFIG_PACKET=y
 CONFIG_UNIX=y
@@ -62,13 +62,13 @@ CONFIG_PROC_KCORE=y
 CONFIG_TMPFS=y
 CONFIG_CRAMFS=y
 # CONFIG_NETWORK_FILESYSTEMS is not set
-CONFIG_DEBUG_INFO=y
-CONFIG_MAGIC_SYSRQ=y
-CONFIG_DETECT_HUNG_TASK=y
-CONFIG_PPC_EARLY_DEBUG=y
 CONFIG_CRYPTO_CBC=y
 CONFIG_CRYPTO_ECB=y
 CONFIG_CRYPTO_PCBC=y
 CONFIG_CRYPTO_MD5=y
 CONFIG_CRYPTO_DES=y
 # CONFIG_CRYPTO_HW is not set
+CONFIG_DEBUG_INFO=y
+CONFIG_MAGIC_SYSRQ=y
+CONFIG_DETECT_HUNG_TASK=y
+CONFIG_PPC_EARLY_DEBUG=y
diff --git a/arch/powerpc/configs/44x/warp_defconfig 
b/arch/powerpc/configs/44x/warp_defconfig
index 6c02f53271cd..4b76897e323f 100644
--- a/arch/powerpc/configs/44x/warp_defconfig
+++ b/arch/powerpc/configs/44x/warp_defconfig
@@ -1,4 +1,3 @@
-CONFIG_44x=y
 CONFIG_LOCALVERSION="-pika"
 # CONFIG_LOCALVERSION_AUTO is not set
 CONFIG_SYSVIPC=y
@@ -7,16 +6,17 @@ CONFIG_IKCONFIG_PROC=y
 CONFIG_LOG_BUF_SHIFT=14
 CONFIG_BLK_DEV_INITRD=y
 CONFIG_EXPERT=y
-CONFIG_MODULES=y
-CONFIG_MODULE_UNLOAD=y
-# CONFIG_B

[PATCH 2/3] powerpc: convert to generic builtin command line

2019-03-01 Thread Daniel Walker
This updates the powerpc code to use the CONFIG_GENERIC_CMDLINE
option.

[maksym.kok...@globallogic.com: add strlcat to prom_init_check.sh
whitelist]
Cc: Daniel Walker 
Cc: Daniel Walker 
Cc: xe-linux-exter...@cisco.com
Signed-off-by: Daniel Walker 
Signed-off-by: Maksym Kokhan 
---
 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(-)

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 8be31261aec8..6321b2a0b87b 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -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
diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c
index fe758cedb93f..d78b1d6fe1c8 100644
--- a/arch/powerpc/kernel/prom.c
+++ b/arch/powerpc/kernel/prom.c
@@ -34,6 +34,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -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);
diff --git a/arch/powerpc/kernel/prom_init.c b/arch/powerpc/kernel/prom_init.c
index f33ff4163a51..e8e9fca22470 100644
--- a/arch/powerpc/kernel/prom_init.c
+++ b/arch/powerpc/kernel/prom_init.c
@@ -30,6 +30,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -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
diff --git a/arch/powerpc/kernel/prom_init_check.sh 
b/arch/powerpc/kernel/prom_init_check.sh
index 667df97d2595..ab2acc8d8b5a 100644
--- a/arch/powerpc/kernel/prom_init_check.sh
+++ b/arch/powerpc/kernel/prom_init_check.sh
@@ -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."
-- 
2.14.1



[PATCH 1/3] add generic builtin command line

2019-03-01 Thread Daniel Walker
This code allows architectures to use a generic builtin command line.
The state of the builtin command line options across architecture is
diverse. On x86 and mips they have pretty much the same code and the
code prepends the builtin command line onto the boot loader provided
one. On powerpc there is only a builtin override and nothing else.

The code in this commit unifies the mips and x86 code into a generic
header file under the CONFIG_GENERIC_CMDLINE option. When this
option is enabled the architecture can call the cmdline_add_builtin()
to add the builtin command line.

[maksym.kok...@globallogic.com: fix cmdline_add_builtin() macro]
Cc: Daniel Walker 
Cc: Daniel Walker 
Cc: xe-linux-exter...@cisco.com
Signed-off-by: Daniel Walker 
Signed-off-by: Maksym Kokhan 
---
 include/linux/cmdline.h | 72 +
 init/Kconfig| 69 +++
 2 files changed, 141 insertions(+)
 create mode 100644 include/linux/cmdline.h

diff --git a/include/linux/cmdline.h b/include/linux/cmdline.h
new file mode 100644
index ..126fa52f55d2
--- /dev/null
+++ b/include/linux/cmdline.h
@@ -0,0 +1,72 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_CMDLINE_H
+#define _LINUX_CMDLINE_H
+
+/*
+ *
+ * Copyright (C) 2015. Cisco Systems, Inc.
+ *
+ * Generic Append/Prepend cmdline support.
+ */
+
+#if defined(CONFIG_GENERIC_CMDLINE) && defined(CONFIG_CMDLINE_BOOL)
+
+#ifndef CONFIG_CMDLINE_OVERRIDE
+/*
+ * This function will append or prepend a builtin command line to the command
+ * line provided by the bootloader. Kconfig options can be used to alter
+ * the behavior of this builtin command line.
+ * @dest: The destination of the final appended/prepended string
+ * @src: The starting string or NULL if there isn't one.
+ * @tmp: temporary space used for prepending
+ * @length: the maximum length of the strings above.
+ */
+static inline void
+_cmdline_add_builtin(char *dest, char *src, char *tmp, unsigned long length)
+{
+   if (src != dest && src != NULL) {
+   strlcpy(dest, " ", length);
+   strlcat(dest, src, length);
+   }
+
+   strlcat(dest, " ", length);
+
+   if (sizeof(CONFIG_CMDLINE_APPEND) > 1)
+   strlcat(dest, CONFIG_CMDLINE_APPEND, length);
+
+   if (sizeof(CONFIG_CMDLINE_PREPEND) > 1) {
+   strlcpy(tmp, CONFIG_CMDLINE_PREPEND, length);
+   strlcat(tmp, " ", length);
+   strlcat(tmp, dest, length);
+   strlcpy(dest, tmp, length);
+   }
+}
+
+#define cmdline_add_builtin_section(dest, src, length, section)\
+{  \
+   if (sizeof(CONFIG_CMDLINE_PREPEND) > 1) {   \
+   static char cmdline_tmp_space[length] section;  \
+   _cmdline_add_builtin(dest, src, cmdline_tmp_space, length); \
+   } else {\
+   _cmdline_add_builtin(dest, src, NULL, length);  \
+   }   \
+}
+#else
+#define cmdline_add_builtin_section(dest, src, length, section)   \
+{ \
+   strlcpy(dest, CONFIG_CMDLINE_PREPEND " " CONFIG_CMDLINE_APPEND,\
+   length);   \
+}
+#endif /* !CONFIG_CMDLINE_OVERRIDE */
+
+#else
+#define cmdline_add_builtin_section(dest, src, length, section) {  \
+   if (src != NULL)   \
+   strlcpy(dest, src, length);\
+}
+#endif /* CONFIG_GENERIC_CMDLINE */
+
+#define cmdline_add_builtin(dest, src, length) \
+   cmdline_add_builtin_section(dest, src, length, __initdata)
+
+#endif /* _LINUX_CMDLINE_H */
diff --git a/init/Kconfig b/init/Kconfig
index a4112e95724a..b59e856511e1 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -1775,6 +1775,75 @@ config PROFILING
 config TRACEPOINTS
bool
 
+config GENERIC_CMDLINE
+   bool
+
+if GENERIC_CMDLINE
+
+config CMDLINE_BOOL
+   bool "Built-in kernel command line"
+   help
+ Allow for specifying boot arguments to the kernel at
+ build time.  On some systems (e.g. embedded ones), it is
+ necessary or convenient to provide some or all of the
+ kernel boot arguments with the kernel itself (that is,
+ to not rely on the boot loader to provide them.)
+
+ To compile command line arguments into the kernel,
+ set this option to 'Y', then fill in the
+ the boot arguments in CONFIG_CMDLINE.
+
+ Systems with fully functional boot loaders (i.e. non-embedded)
+ should leave this 

Re: linux-next: manual merge of the cisco tree with the vfs tree

2019-01-14 Thread Daniel Walker
On Tue, Jan 15, 2019 at 09:33:30AM +1100, Stephen Rothwell wrote:
> Hi Daniel,
> 
> On Tue, 2 Oct 2018 16:29:23 +1000 Stephen Rothwell  
> wrote:
> >
> > Today's linux-next merge of the cisco tree got a conflict in:
> > 
> >   arch/x86/kernel/setup.c
> > 
> > between commit:
> > 
> >   dcf8001d292b ("vfs: Suppress MS_* flag defs within the kernel unless 
> > explicitly enabled")
> > 
> > from the vfs tree and commit:
> > 
> >   2c070709ea75 ("This updates the x86 code to use the 
> > CONFIG_GENERIC_CMDLINE")
> > 
> > from the cisco tree.
> > 
> > I fixed it up (see below) and can carry the fix as necessary. This
> > is now fixed as far as linux-next is concerned, but any non trivial
> > conflicts should be mentioned to your upstream maintainer when your tree
> > is submitted for merging.  You may also want to consider cooperating
> > with the maintainer of the conflicting tree to minimise any particularly
> > complex conflicts.
> > 
> > -- 
> > Cheers,
> > Stephen Rothwell
> > 
> > diff --cc arch/x86/kernel/setup.c
> > index e493202bf265,ee109f490b22..
> > --- a/arch/x86/kernel/setup.c
> > +++ b/arch/x86/kernel/setup.c
> > @@@ -51,7 -51,7 +51,8 @@@
> >   #include 
> >   #include 
> >   #include 
> >  +#include 
> > + #include 
> >   
> >   #include 
> >   #include 
> 
> This is now a conflict between the cicso tree and Linus' tree.

I did a rebase after your original made this. I'm not sure it's needed any
longer. However, I was planning to rebase my tree again on top of the latest
Linus tree. How would you like to proceed ?

Daniel


Re: [PATCH 1/3] add generic builtin command line

2018-11-29 Thread Daniel Walker
On Wed, Nov 28, 2018 at 09:12:12PM -0800, Andrew Morton wrote:
> On Fri,  9 Nov 2018 09:34:31 -0800 Daniel Walker  wrote:
> 
> > This code allows architectures to use a generic builtin command line.
> > The state of the builtin command line options across architecture is
> > diverse. On x86 and mips they have pretty much the same code and the
> > code prepends the builtin command line onto the boot loader provided
> > one. On powerpc there is only a builtin override and nothing else.
> > 
> > The code in this commit unifies the mips and x86 code into a generic
> > header file under the CONFIG_GENERIC_CMDLINE option. When this
> > option is enabled the architecture can call the cmdline_add_builtin()
> > to add the builtin command line.
> 
> I'm not sure what's happened to this and I haven't seen the other two
> patches but...

It's been sitting in -next since the last merge window. 

> 
> > [maksym.kok...@globallogic.com: fix cmdline_add_builtin() macro]
> > Cc: Daniel Walker 
> > Cc: Daniel Walker 
> > Cc: xe-linux-exter...@cisco.com
> > Signed-off-by: Daniel Walker 
> > Signed-off-by: Maksym Kokhan 
> 
> Two SOB's is nice, but some reviews and acks would be nicer.
 
Would love to add some, but no one is reviewing it.. 

> > --- /dev/null
> > +++ b/include/linux/cmdline.h
> > @@ -0,0 +1,79 @@
> > +/* SPDX-License-Identifier: GPL-2.0 */
> > +#ifndef _LINUX_CMDLINE_H
> > +#define _LINUX_CMDLINE_H
> > +
> > +/*
> > + *
> > + * Copyright (C) 2015. Cisco Systems, Inc.
> > + *
> > + * Generic Append/Prepend cmdline support.
> > + */
> > +
> > +#if defined(CONFIG_GENERIC_CMDLINE) && defined(CONFIG_CMDLINE_BOOL)
> > +
> > +#ifndef CONFIG_CMDLINE_OVERRIDE
> > +/*
> > + * This function will append or prepend a builtin command line to the 
> > command
> > + * line provided by the bootloader. Kconfig options can be used to alter
> > + * the behavior of this builtin command line.
> > + * @dest: The destination of the final appended/prepended string
> > + * @src: The starting string or NULL if there isn't one.
> > + * @tmp: temporary space used for prepending
> > + * @length: the maximum length of the strings above.
> > + */
> > +static inline void
> > +_cmdline_add_builtin(char *dest, char *src, char *tmp, unsigned long 
> > length)
> > +{
> > +   if (src != dest && src != NULL) {
> > +   strlcpy(dest, " ", length);
> > +   strlcat(dest, src, length);
> > +   }
> > +
> > +   strlcat(dest, " ", length);
> > +
> > +   if (sizeof(CONFIG_CMDLINE_APPEND) > 1)
> > +   strlcat(dest, CONFIG_CMDLINE_APPEND, length);
> > +
> > +   /*
> > +* You need to convert you old style CONFIG_CMDLINE to use
> 
> "your"
> 
> > +* the prepend, or append defines. Some architectures use one
> 
> "one and"
> 
> > +* some use the other. You need to figure out which ones is
> 
> "one"

Can fix these..


> 
> > +* right for your situation. I would recommend prepending
> > +* because it's the safest (i.e. CONFIG_CMDLINE_PREPEND).
> > +*/
> > +   BUILD_BUG_ON(sizeof(CONFIG_CMDLINE) != 1);
> > +
> > +   if (sizeof(CONFIG_CMDLINE_PREPEND) > 1) {
> > +   strlcpy(tmp, CONFIG_CMDLINE_PREPEND, length);
> > +   strlcat(tmp, " ", length);
> > +   strlcat(tmp, dest, length);
> > +   strlcpy(dest, tmp, length);
> > +   }
> > +}
> 
> And... holy cow.  Does this monster really need to be inlined?
> 
> > +#define cmdline_add_builtin(dest, src, length) 
> > \
> > +{  \
> > +   if (sizeof(CONFIG_CMDLINE_PREPEND) > 1) {   \
> > +   static char cmdline_tmp_space[length] __initdata;   \
> > +   _cmdline_add_builtin(dest, src, cmdline_tmp_space, length); \
> > +   } else {\
> > +   _cmdline_add_builtin(dest, src, NULL, length);  \
> > +   }   \
> > +}
> 
> And this will generate __initdata storage at each invocation site.  Can
> it be redone in real, non-inlined C?


It's intended to be used once, maybe twice, per architecture. Powerpc uses it
twice I think. There's no reason for it to be used more than twice, and it 
replaces
code which is similar to the code above. I can' imagine a situation where people
go nuts and start calling this everywhere.

So it seemed easier to just inline it.

Daniel


Re: [PATCH 1/3] add generic builtin command line

2018-11-29 Thread Daniel Walker
On Wed, Nov 28, 2018 at 09:12:12PM -0800, Andrew Morton wrote:
> On Fri,  9 Nov 2018 09:34:31 -0800 Daniel Walker  wrote:
> 
> > This code allows architectures to use a generic builtin command line.
> > The state of the builtin command line options across architecture is
> > diverse. On x86 and mips they have pretty much the same code and the
> > code prepends the builtin command line onto the boot loader provided
> > one. On powerpc there is only a builtin override and nothing else.
> > 
> > The code in this commit unifies the mips and x86 code into a generic
> > header file under the CONFIG_GENERIC_CMDLINE option. When this
> > option is enabled the architecture can call the cmdline_add_builtin()
> > to add the builtin command line.
> 
> I'm not sure what's happened to this and I haven't seen the other two
> patches but...

It's been sitting in -next since the last merge window. 

> 
> > [maksym.kok...@globallogic.com: fix cmdline_add_builtin() macro]
> > Cc: Daniel Walker 
> > Cc: Daniel Walker 
> > Cc: xe-linux-exter...@cisco.com
> > Signed-off-by: Daniel Walker 
> > Signed-off-by: Maksym Kokhan 
> 
> Two SOB's is nice, but some reviews and acks would be nicer.
 
Would love to add some, but no one is reviewing it.. 

> > --- /dev/null
> > +++ b/include/linux/cmdline.h
> > @@ -0,0 +1,79 @@
> > +/* SPDX-License-Identifier: GPL-2.0 */
> > +#ifndef _LINUX_CMDLINE_H
> > +#define _LINUX_CMDLINE_H
> > +
> > +/*
> > + *
> > + * Copyright (C) 2015. Cisco Systems, Inc.
> > + *
> > + * Generic Append/Prepend cmdline support.
> > + */
> > +
> > +#if defined(CONFIG_GENERIC_CMDLINE) && defined(CONFIG_CMDLINE_BOOL)
> > +
> > +#ifndef CONFIG_CMDLINE_OVERRIDE
> > +/*
> > + * This function will append or prepend a builtin command line to the 
> > command
> > + * line provided by the bootloader. Kconfig options can be used to alter
> > + * the behavior of this builtin command line.
> > + * @dest: The destination of the final appended/prepended string
> > + * @src: The starting string or NULL if there isn't one.
> > + * @tmp: temporary space used for prepending
> > + * @length: the maximum length of the strings above.
> > + */
> > +static inline void
> > +_cmdline_add_builtin(char *dest, char *src, char *tmp, unsigned long 
> > length)
> > +{
> > +   if (src != dest && src != NULL) {
> > +   strlcpy(dest, " ", length);
> > +   strlcat(dest, src, length);
> > +   }
> > +
> > +   strlcat(dest, " ", length);
> > +
> > +   if (sizeof(CONFIG_CMDLINE_APPEND) > 1)
> > +   strlcat(dest, CONFIG_CMDLINE_APPEND, length);
> > +
> > +   /*
> > +* You need to convert you old style CONFIG_CMDLINE to use
> 
> "your"
> 
> > +* the prepend, or append defines. Some architectures use one
> 
> "one and"
> 
> > +* some use the other. You need to figure out which ones is
> 
> "one"

Can fix these..


> 
> > +* right for your situation. I would recommend prepending
> > +* because it's the safest (i.e. CONFIG_CMDLINE_PREPEND).
> > +*/
> > +   BUILD_BUG_ON(sizeof(CONFIG_CMDLINE) != 1);
> > +
> > +   if (sizeof(CONFIG_CMDLINE_PREPEND) > 1) {
> > +   strlcpy(tmp, CONFIG_CMDLINE_PREPEND, length);
> > +   strlcat(tmp, " ", length);
> > +   strlcat(tmp, dest, length);
> > +   strlcpy(dest, tmp, length);
> > +   }
> > +}
> 
> And... holy cow.  Does this monster really need to be inlined?
> 
> > +#define cmdline_add_builtin(dest, src, length) 
> > \
> > +{  \
> > +   if (sizeof(CONFIG_CMDLINE_PREPEND) > 1) {   \
> > +   static char cmdline_tmp_space[length] __initdata;   \
> > +   _cmdline_add_builtin(dest, src, cmdline_tmp_space, length); \
> > +   } else {\
> > +   _cmdline_add_builtin(dest, src, NULL, length);  \
> > +   }   \
> > +}
> 
> And this will generate __initdata storage at each invocation site.  Can
> it be redone in real, non-inlined C?


It's intended to be used once, maybe twice, per architecture. Powerpc uses it
twice I think. There's no reason for it to be used more than twice, and it 
replaces
code which is similar to the code above. I can' imagine a situation where people
go nuts and start calling this everywhere.

So it seemed easier to just inline it.

Daniel


Re: [PATCH] jffs2: implement mount option to configure endianness

2018-11-13 Thread Daniel Walker
On Mon, Nov 12, 2018 at 03:43:37PM -0800, David Woodhouse wrote:
> 
> That can't hurt. We should probably look at the time elapsed before you
> can *write* to it (when the background scan and crc checking is
> complete) rather than just reading.
> 


Here are more data points. This is again with 100meg mtdram size. I made a 
script which does the mount and umount, then perf ran that 100 times over and
averaged the results.

Baseline,

 Performance counter stats for 'bash test.sh' (100 runs):

111.414863 task-clock#0.637 CPUs utilized   
 ( +-  0.07% )
41 context-switches  #0.371 K/sec   
 ( +-  0.50% )
 3 cpu-migrations#0.023 K/sec   
 ( +-  2.44% )
   405 page-faults   #0.004 M/sec   
 ( +-  0.05% )
 147235193 cycles#1.322 GHz 
 ( +-  0.47% ) [53.76%]
  53688988 stalled-cycles-frontend   #   36.46% frontend cycles idle
 ( +-  2.59% ) [45.13%]
  21691444 stalled-cycles-backend#   14.73% backend  cycles idle
 ( +-  5.81% ) [68.50%]
 138433181 instructions  #0.94  insns per cycle
 #0.39  stalled cycles per insn 
 ( +-  0.88% ) [88.11%]
  25882823 branches  #  232.310 M/sec   
 ( +-  1.42% ) [85.33%]
644457 branch-misses #2.49% of all branches 
 ( +-  5.19% ) [74.30%]

   0.175012976 seconds time elapsed 
 ( +-  0.58% )


With Nikunj's patch,


 Performance counter stats for 'bash test.sh' (100 runs):

110.436715 task-clock#0.625 CPUs utilized   
 ( +-  0.07% )
41 context-switches  #0.373 K/sec   
 ( +-  0.58% )
 3 cpu-migrations#0.024 K/sec   
 ( +-  2.18% )
   405 page-faults   #0.004 M/sec   
 ( +-  0.05% )
 145964351 cycles#1.322 GHz 
 ( +-  0.49% ) [53.68%]
  47504491 stalled-cycles-frontend   #   32.55% frontend cycles idle
 ( +-  2.96% ) [55.47%]
  20481138 stalled-cycles-backend#   14.03% backend  cycles idle
 ( +-  6.18% ) [71.19%]
 134947645 instructions  #0.92  insns per cycle
 #0.35  stalled cycles per insn 
 ( +-  1.18% ) [82.19%]
  25343960 branches  #  229.489 M/sec   
 ( +-  1.65% ) [82.50%]
693642 branch-misses #2.74% of all branches 
 ( +-  5.29% ) [70.06%]

   0.176606850 seconds time elapsed 
 ( +-  0.50% )



This seems to show an 0.91% speed elapsed time difference. Most of the rest of 
it seems very similar.


Daniel


Re: [PATCH] jffs2: implement mount option to configure endianness

2018-11-13 Thread Daniel Walker
On Mon, Nov 12, 2018 at 03:43:37PM -0800, David Woodhouse wrote:
> 
> That can't hurt. We should probably look at the time elapsed before you
> can *write* to it (when the background scan and crc checking is
> complete) rather than just reading.
> 


Here are more data points. This is again with 100meg mtdram size. I made a 
script which does the mount and umount, then perf ran that 100 times over and
averaged the results.

Baseline,

 Performance counter stats for 'bash test.sh' (100 runs):

111.414863 task-clock#0.637 CPUs utilized   
 ( +-  0.07% )
41 context-switches  #0.371 K/sec   
 ( +-  0.50% )
 3 cpu-migrations#0.023 K/sec   
 ( +-  2.44% )
   405 page-faults   #0.004 M/sec   
 ( +-  0.05% )
 147235193 cycles#1.322 GHz 
 ( +-  0.47% ) [53.76%]
  53688988 stalled-cycles-frontend   #   36.46% frontend cycles idle
 ( +-  2.59% ) [45.13%]
  21691444 stalled-cycles-backend#   14.73% backend  cycles idle
 ( +-  5.81% ) [68.50%]
 138433181 instructions  #0.94  insns per cycle
 #0.39  stalled cycles per insn 
 ( +-  0.88% ) [88.11%]
  25882823 branches  #  232.310 M/sec   
 ( +-  1.42% ) [85.33%]
644457 branch-misses #2.49% of all branches 
 ( +-  5.19% ) [74.30%]

   0.175012976 seconds time elapsed 
 ( +-  0.58% )


With Nikunj's patch,


 Performance counter stats for 'bash test.sh' (100 runs):

110.436715 task-clock#0.625 CPUs utilized   
 ( +-  0.07% )
41 context-switches  #0.373 K/sec   
 ( +-  0.58% )
 3 cpu-migrations#0.024 K/sec   
 ( +-  2.18% )
   405 page-faults   #0.004 M/sec   
 ( +-  0.05% )
 145964351 cycles#1.322 GHz 
 ( +-  0.49% ) [53.68%]
  47504491 stalled-cycles-frontend   #   32.55% frontend cycles idle
 ( +-  2.96% ) [55.47%]
  20481138 stalled-cycles-backend#   14.03% backend  cycles idle
 ( +-  6.18% ) [71.19%]
 134947645 instructions  #0.92  insns per cycle
 #0.35  stalled cycles per insn 
 ( +-  1.18% ) [82.19%]
  25343960 branches  #  229.489 M/sec   
 ( +-  1.65% ) [82.50%]
693642 branch-misses #2.74% of all branches 
 ( +-  5.29% ) [70.06%]

   0.176606850 seconds time elapsed 
 ( +-  0.50% )



This seems to show an 0.91% speed elapsed time difference. Most of the rest of 
it seems very similar.


Daniel


Re: [PATCH] jffs2: implement mount option to configure endianness

2018-11-12 Thread Daniel Walker
On Mon, Nov 12, 2018 at 03:43:37PM -0800, David Woodhouse wrote:
> 
> That can't hurt. We should probably look at the time elapsed before you
> can *write* to it (when the background scan and crc checking is
> complete) rather than just reading.
> 


I'm not sure how to test that, but I tried this,

mount -t jffs2 mtd7 /mnt ; perf stat -B dd if=/dev/zero of=/mnt/test bs
1 count=1;

What would you suggest for testing this ?

Daniel


Re: [PATCH] jffs2: implement mount option to configure endianness

2018-11-12 Thread Daniel Walker
On Mon, Nov 12, 2018 at 03:43:37PM -0800, David Woodhouse wrote:
> 
> That can't hurt. We should probably look at the time elapsed before you
> can *write* to it (when the background scan and crc checking is
> complete) rather than just reading.
> 


I'm not sure how to test that, but I tried this,

mount -t jffs2 mtd7 /mnt ; perf stat -B dd if=/dev/zero of=/mnt/test bs
1 count=1;

What would you suggest for testing this ?

Daniel


Re: [PATCH] jffs2: implement mount option to configure endianness

2018-11-12 Thread Daniel Walker
On Mon, Nov 12, 2018 at 03:11:32PM -0800, David Woodhouse wrote:
> On Mon, 2018-11-12 at 14:50 -0800, Daniel Walker wrote:
> >  Performance counter stats for 'mount -t jffs2 /dev/mtdblock7 /mnt':
> 
> Hm, how many decades will it take for the 'mtdblock' thing to die?
> JFFS2 doesn't use block devices :)

mount wouldn't mount unless I use it. It complained "not a block device."

sh-4.2# mount -t jffs2 /dev/mtd7 /mnt
mount:  /dev/mtd7 is not a block device

> > It looks like the took slightly more than twice as long to mount.
> 
> Assuming that's repeatable, it seems moderately suboptimal.

I don't understand how the cycles are lower, but the time is longer. I suppose
it could be measuring the time including when another process was running and
mount as waiting.. 

Looks like it's not repeatable .. Another run and the time is similar to the
baseline.

sh-4.2# perf stat -B mount -t jffs2 /dev/mtdblock7 /mnt
jffs2: Flash size not aligned to erasesize, reducing to 99944KiB

 Performance counter stats for 'mount -t jffs2 /dev/mtdblock7 /mnt':

100.468768 task-clock#0.750 CPUs utilized
14 context-switches  #0.139 K/sec
 0 cpu-migrations#0.000 K/sec
94 page-faults   #0.936 K/sec
 132105969 cycles#1.315 GHz 
[94.26%]
  27915494 stalled-cycles-frontend   #   21.13% frontend cycles idle
[91.88%]
  10214813 stalled-cycles-backend#7.73% backend  cycles idle
[92.04%]
 137814560 instructions  #1.04  insns per cycle
 #0.20  stalled cycles per insn 
[92.04%]
  15395620 branches  #  153.238 M/sec   
[19.29%]
   1240507 branch-misses #8.06% of all branches 
[17.87%]

   0.133987804 seconds time elapsed



Should I test increasing the mtdram size ?

Daniel


Re: [PATCH] jffs2: implement mount option to configure endianness

2018-11-12 Thread Daniel Walker
On Mon, Nov 12, 2018 at 03:11:32PM -0800, David Woodhouse wrote:
> On Mon, 2018-11-12 at 14:50 -0800, Daniel Walker wrote:
> >  Performance counter stats for 'mount -t jffs2 /dev/mtdblock7 /mnt':
> 
> Hm, how many decades will it take for the 'mtdblock' thing to die?
> JFFS2 doesn't use block devices :)

mount wouldn't mount unless I use it. It complained "not a block device."

sh-4.2# mount -t jffs2 /dev/mtd7 /mnt
mount:  /dev/mtd7 is not a block device

> > It looks like the took slightly more than twice as long to mount.
> 
> Assuming that's repeatable, it seems moderately suboptimal.

I don't understand how the cycles are lower, but the time is longer. I suppose
it could be measuring the time including when another process was running and
mount as waiting.. 

Looks like it's not repeatable .. Another run and the time is similar to the
baseline.

sh-4.2# perf stat -B mount -t jffs2 /dev/mtdblock7 /mnt
jffs2: Flash size not aligned to erasesize, reducing to 99944KiB

 Performance counter stats for 'mount -t jffs2 /dev/mtdblock7 /mnt':

100.468768 task-clock#0.750 CPUs utilized
14 context-switches  #0.139 K/sec
 0 cpu-migrations#0.000 K/sec
94 page-faults   #0.936 K/sec
 132105969 cycles#1.315 GHz 
[94.26%]
  27915494 stalled-cycles-frontend   #   21.13% frontend cycles idle
[91.88%]
  10214813 stalled-cycles-backend#7.73% backend  cycles idle
[92.04%]
 137814560 instructions  #1.04  insns per cycle
 #0.20  stalled cycles per insn 
[92.04%]
  15395620 branches  #  153.238 M/sec   
[19.29%]
   1240507 branch-misses #8.06% of all branches 
[17.87%]

   0.133987804 seconds time elapsed



Should I test increasing the mtdram size ?

Daniel


Re: [PATCH] jffs2: implement mount option to configure endianness

2018-11-12 Thread Daniel Walker
On Mon, Nov 12, 2018 at 01:43:33PM -0800, Daniel Walker wrote:
> On Thu, Nov 08, 2018 at 07:47:08PM +, David Woodhouse wrote:
> > On Thu, 2018-11-08 at 18:01 +, Nikunj Kela (nkela) wrote:
> > > But we can hypothesise and handwave about it until the cows come home;
> > > I'd like to see a real test of whether it actually makes a difference
> > > that we care about.
> > > 
> > > If it does, one option might be to just build separate versions of
> > > scan.c for each endianness, since that's the critical path we care
> > > about.
> > > 
> > > I wonder if this feature is really that important that we need to 
> > > duplicate the drivers.
> > > Also, it might take some time for me to find some device that I can run 
> > > the tests with and without this patch.
> > 
> > Hm?
> > 
> > # modprobe mtdram size=16384
> > # mount -tjffs2 mtd0 /mnt
> > # cp -av .git /mnt # until it fills up
> > # umount /mnt
> > # perf record mount -tjffs2 mtd0 /mnt
> > 
> > On my desktop 'perf' only gets about 12 samples from that, so it's not
> > ideal. But you can make the mtdram device bigger, use something other
> > than my shiny new laptop, and use a higher sample frequency from 'perf'
> > and you should be able to get some vaguely meaningful results.
> > 
> 

Made a little mistake. The first tests were with Nikunj's very first version
which was just a pure Kconfig option. I reran the test of the second version and
increased the mtdram space to 100megs.

baseline below,

sh-4.2# perf stat -B mount -t jffs2 /dev/mtdblock7 /mnt
jffs2: Flash size not aligned to erasesize, reducing to 99944KiB

 Performance counter stats for 'mount -t jffs2 /dev/mtdblock7 /mnt':

100.303072 task-clock#0.775 CPUs utilized  
19 context-switches  #0.189 K/sec  
 0 cpu-migrations#0.000 K/sec  
94 page-faults   #0.937 K/sec  
 134135872 cycles#1.337 GHz 
[92.88%]
  29217497 stalled-cycles-frontend   #   21.78% frontend cycles idle
[92.02%]
  10493221 stalled-cycles-backend#7.82% backend  cycles idle
[92.05%]
 136740541 instructions  #1.02  insns per cycle
 #0.21  stalled cycles per insn 
[92.04%]
  14639149 branches  #  145.949 M/sec   
[19.06%]
   1384856 branch-misses #9.46% of all branches 
[16.29%]

   0.129377322 seconds time elapsed


This is with the mount option changes added.


sh-4.2# perf stat -B mount -t jffs2 /dev/mtdblock7 /mnt
jffs2: Flash size not aligned to erasesize, reducing to 99944KiB

 Performance counter stats for 'mount -t jffs2 /dev/mtdblock7 /mnt':

100.516160 task-clock#0.315 CPUs utilized  
14 context-switches  #0.139 K/sec  
 0 cpu-migrations#0.000 K/sec  
94 page-faults   #0.935 K/sec  
 129255757 cycles#1.286 GHz 
[19.32%]
  26930446 stalled-cycles-frontend   #   20.84% frontend cycles idle
[92.00%]
  10068627 stalled-cycles-backend#7.79% backend  cycles idle
[92.05%]
 138000320 instructions  #1.07  insns per cycle
 #0.20  stalled cycles per insn 
[92.04%]
  26158985 branches  #  260.247 M/sec   
[90.09%]
   1242606 branch-misses #4.75% of all branches 
[19.24%]

   0.319593555 seconds time elapsed


It looks like the took slightly more than twice as long to mount.

Daniel


Re: [PATCH] jffs2: implement mount option to configure endianness

2018-11-12 Thread Daniel Walker
On Mon, Nov 12, 2018 at 01:43:33PM -0800, Daniel Walker wrote:
> On Thu, Nov 08, 2018 at 07:47:08PM +, David Woodhouse wrote:
> > On Thu, 2018-11-08 at 18:01 +, Nikunj Kela (nkela) wrote:
> > > But we can hypothesise and handwave about it until the cows come home;
> > > I'd like to see a real test of whether it actually makes a difference
> > > that we care about.
> > > 
> > > If it does, one option might be to just build separate versions of
> > > scan.c for each endianness, since that's the critical path we care
> > > about.
> > > 
> > > I wonder if this feature is really that important that we need to 
> > > duplicate the drivers.
> > > Also, it might take some time for me to find some device that I can run 
> > > the tests with and without this patch.
> > 
> > Hm?
> > 
> > # modprobe mtdram size=16384
> > # mount -tjffs2 mtd0 /mnt
> > # cp -av .git /mnt # until it fills up
> > # umount /mnt
> > # perf record mount -tjffs2 mtd0 /mnt
> > 
> > On my desktop 'perf' only gets about 12 samples from that, so it's not
> > ideal. But you can make the mtdram device bigger, use something other
> > than my shiny new laptop, and use a higher sample frequency from 'perf'
> > and you should be able to get some vaguely meaningful results.
> > 
> 

Made a little mistake. The first tests were with Nikunj's very first version
which was just a pure Kconfig option. I reran the test of the second version and
increased the mtdram space to 100megs.

baseline below,

sh-4.2# perf stat -B mount -t jffs2 /dev/mtdblock7 /mnt
jffs2: Flash size not aligned to erasesize, reducing to 99944KiB

 Performance counter stats for 'mount -t jffs2 /dev/mtdblock7 /mnt':

100.303072 task-clock#0.775 CPUs utilized  
19 context-switches  #0.189 K/sec  
 0 cpu-migrations#0.000 K/sec  
94 page-faults   #0.937 K/sec  
 134135872 cycles#1.337 GHz 
[92.88%]
  29217497 stalled-cycles-frontend   #   21.78% frontend cycles idle
[92.02%]
  10493221 stalled-cycles-backend#7.82% backend  cycles idle
[92.05%]
 136740541 instructions  #1.02  insns per cycle
 #0.21  stalled cycles per insn 
[92.04%]
  14639149 branches  #  145.949 M/sec   
[19.06%]
   1384856 branch-misses #9.46% of all branches 
[16.29%]

   0.129377322 seconds time elapsed


This is with the mount option changes added.


sh-4.2# perf stat -B mount -t jffs2 /dev/mtdblock7 /mnt
jffs2: Flash size not aligned to erasesize, reducing to 99944KiB

 Performance counter stats for 'mount -t jffs2 /dev/mtdblock7 /mnt':

100.516160 task-clock#0.315 CPUs utilized  
14 context-switches  #0.139 K/sec  
 0 cpu-migrations#0.000 K/sec  
94 page-faults   #0.935 K/sec  
 129255757 cycles#1.286 GHz 
[19.32%]
  26930446 stalled-cycles-frontend   #   20.84% frontend cycles idle
[92.00%]
  10068627 stalled-cycles-backend#7.79% backend  cycles idle
[92.05%]
 138000320 instructions  #1.07  insns per cycle
 #0.20  stalled cycles per insn 
[92.04%]
  26158985 branches  #  260.247 M/sec   
[90.09%]
   1242606 branch-misses #4.75% of all branches 
[19.24%]

   0.319593555 seconds time elapsed


It looks like the took slightly more than twice as long to mount.

Daniel


Re: [PATCH] jffs2: implement mount option to configure endianness

2018-11-12 Thread Daniel Walker
On Thu, Nov 08, 2018 at 07:47:08PM +, David Woodhouse wrote:
> On Thu, 2018-11-08 at 18:01 +, Nikunj Kela (nkela) wrote:
> > But we can hypothesise and handwave about it until the cows come home;
> > I'd like to see a real test of whether it actually makes a difference
> > that we care about.
> > 
> > If it does, one option might be to just build separate versions of
> > scan.c for each endianness, since that's the critical path we care
> > about.
> > 
> > I wonder if this feature is really that important that we need to duplicate 
> > the drivers.
> > Also, it might take some time for me to find some device that I can run the 
> > tests with and without this patch.
> 
> Hm?
> 
> # modprobe mtdram size=16384
> # mount -tjffs2 mtd0 /mnt
> # cp -av .git /mnt # until it fills up
> # umount /mnt
> # perf record mount -tjffs2 mtd0 /mnt
> 
> On my desktop 'perf' only gets about 12 samples from that, so it's not
> ideal. But you can make the mtdram device bigger, use something other
> than my shiny new laptop, and use a higher sample frequency from 'perf'
> and you should be able to get some vaguely meaningful results.
> 

10 meg MTDRAM device baseline without any changes,

sh-4.2# perf stat -B  mount -tjffs2 /dev/mtdblock7 /mnt
jffs2: Flash size not aligned to erasesize, reducing to 9920KiB

 Performance counter stats for 'mount -tjffs2 /dev/mtdblock7 /mnt':

 74.922624 task-clock#0.820 CPUs utilized  
14 context-switches  #0.187 K/sec  
 0 cpu-migrations#0.000 K/sec  
94 page-faults   #0.001 M/sec  
 103274114 cycles#1.378 GHz 
[ 6.65%]
   1887555 stalled-cycles-frontend   #1.83% frontend cycles idle   
   1688520 stalled-cycles-backend#1.63% backend  cycles idle   
 106423876 instructions  #1.03  insns per cycle
 #0.02  stalled cycles per insn
  21325416 branches  #  284.633 M/sec   
[97.41%]
104797 branch-misses #0.49% of all branches 
[95.20%]

   0.091398368 seconds time elapsed


Same partition size, adding in the patch from Nikunj set to Native,

sh-4.2# perf stat -B mount -t jffs2 /dev/mtdblock7 /mnt
jffs2: Flash size not aligned to erasesize, reducing to 9920KiB

 Performance counter stats for 'mount -t jffs2 /dev/mtdblock7 /mnt':

 75.223488 task-clock#0.736 CPUs utilized  
17 context-switches  #0.226 K/sec  
 0 cpu-migrations#0.000 K/sec  
94 page-faults   #0.001 M/sec  
 100815917 cycles#1.340 GHz
  16561335 stalled-cycles-frontend   #   16.43% frontend cycles idle   
   2991700 stalled-cycles-backend#2.97% backend  cycles idle   
 106536662 instructions  #1.06  insns per cycle
 #0.16  stalled cycles per insn
  10931326 branches  #  145.318 M/sec   
[ 4.13%]
931410 branch-misses #8.52% of all branches 
[ 2.87%]

   0.102157784 seconds time elapsed


I'm not sure this tells us very much. If anything it looks like not much has 
changes.

Daniel


Re: [PATCH] jffs2: implement mount option to configure endianness

2018-11-12 Thread Daniel Walker
On Thu, Nov 08, 2018 at 07:47:08PM +, David Woodhouse wrote:
> On Thu, 2018-11-08 at 18:01 +, Nikunj Kela (nkela) wrote:
> > But we can hypothesise and handwave about it until the cows come home;
> > I'd like to see a real test of whether it actually makes a difference
> > that we care about.
> > 
> > If it does, one option might be to just build separate versions of
> > scan.c for each endianness, since that's the critical path we care
> > about.
> > 
> > I wonder if this feature is really that important that we need to duplicate 
> > the drivers.
> > Also, it might take some time for me to find some device that I can run the 
> > tests with and without this patch.
> 
> Hm?
> 
> # modprobe mtdram size=16384
> # mount -tjffs2 mtd0 /mnt
> # cp -av .git /mnt # until it fills up
> # umount /mnt
> # perf record mount -tjffs2 mtd0 /mnt
> 
> On my desktop 'perf' only gets about 12 samples from that, so it's not
> ideal. But you can make the mtdram device bigger, use something other
> than my shiny new laptop, and use a higher sample frequency from 'perf'
> and you should be able to get some vaguely meaningful results.
> 

10 meg MTDRAM device baseline without any changes,

sh-4.2# perf stat -B  mount -tjffs2 /dev/mtdblock7 /mnt
jffs2: Flash size not aligned to erasesize, reducing to 9920KiB

 Performance counter stats for 'mount -tjffs2 /dev/mtdblock7 /mnt':

 74.922624 task-clock#0.820 CPUs utilized  
14 context-switches  #0.187 K/sec  
 0 cpu-migrations#0.000 K/sec  
94 page-faults   #0.001 M/sec  
 103274114 cycles#1.378 GHz 
[ 6.65%]
   1887555 stalled-cycles-frontend   #1.83% frontend cycles idle   
   1688520 stalled-cycles-backend#1.63% backend  cycles idle   
 106423876 instructions  #1.03  insns per cycle
 #0.02  stalled cycles per insn
  21325416 branches  #  284.633 M/sec   
[97.41%]
104797 branch-misses #0.49% of all branches 
[95.20%]

   0.091398368 seconds time elapsed


Same partition size, adding in the patch from Nikunj set to Native,

sh-4.2# perf stat -B mount -t jffs2 /dev/mtdblock7 /mnt
jffs2: Flash size not aligned to erasesize, reducing to 9920KiB

 Performance counter stats for 'mount -t jffs2 /dev/mtdblock7 /mnt':

 75.223488 task-clock#0.736 CPUs utilized  
17 context-switches  #0.226 K/sec  
 0 cpu-migrations#0.000 K/sec  
94 page-faults   #0.001 M/sec  
 100815917 cycles#1.340 GHz
  16561335 stalled-cycles-frontend   #   16.43% frontend cycles idle   
   2991700 stalled-cycles-backend#2.97% backend  cycles idle   
 106536662 instructions  #1.06  insns per cycle
 #0.16  stalled cycles per insn
  10931326 branches  #  145.318 M/sec   
[ 4.13%]
931410 branch-misses #8.52% of all branches 
[ 2.87%]

   0.102157784 seconds time elapsed


I'm not sure this tells us very much. If anything it looks like not much has 
changes.

Daniel


[PATCH 1/3] add generic builtin command line

2018-11-09 Thread Daniel Walker
This code allows architectures to use a generic builtin command line.
The state of the builtin command line options across architecture is
diverse. On x86 and mips they have pretty much the same code and the
code prepends the builtin command line onto the boot loader provided
one. On powerpc there is only a builtin override and nothing else.

The code in this commit unifies the mips and x86 code into a generic
header file under the CONFIG_GENERIC_CMDLINE option. When this
option is enabled the architecture can call the cmdline_add_builtin()
to add the builtin command line.

[maksym.kok...@globallogic.com: fix cmdline_add_builtin() macro]
Cc: Daniel Walker 
Cc: Daniel Walker 
Cc: xe-linux-exter...@cisco.com
Signed-off-by: Daniel Walker 
Signed-off-by: Maksym Kokhan 
---
 include/linux/cmdline.h | 79 +
 init/Kconfig| 72 
 2 files changed, 151 insertions(+)
 create mode 100644 include/linux/cmdline.h

diff --git a/include/linux/cmdline.h b/include/linux/cmdline.h
new file mode 100644
index ..e7e5cdd66d3a
--- /dev/null
+++ b/include/linux/cmdline.h
@@ -0,0 +1,79 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_CMDLINE_H
+#define _LINUX_CMDLINE_H
+
+/*
+ *
+ * Copyright (C) 2015. Cisco Systems, Inc.
+ *
+ * Generic Append/Prepend cmdline support.
+ */
+
+#if defined(CONFIG_GENERIC_CMDLINE) && defined(CONFIG_CMDLINE_BOOL)
+
+#ifndef CONFIG_CMDLINE_OVERRIDE
+/*
+ * This function will append or prepend a builtin command line to the command
+ * line provided by the bootloader. Kconfig options can be used to alter
+ * the behavior of this builtin command line.
+ * @dest: The destination of the final appended/prepended string
+ * @src: The starting string or NULL if there isn't one.
+ * @tmp: temporary space used for prepending
+ * @length: the maximum length of the strings above.
+ */
+static inline void
+_cmdline_add_builtin(char *dest, char *src, char *tmp, unsigned long length)
+{
+   if (src != dest && src != NULL) {
+   strlcpy(dest, " ", length);
+   strlcat(dest, src, length);
+   }
+
+   strlcat(dest, " ", length);
+
+   if (sizeof(CONFIG_CMDLINE_APPEND) > 1)
+   strlcat(dest, CONFIG_CMDLINE_APPEND, length);
+
+   /*
+* You need to convert you old style CONFIG_CMDLINE to use
+* the prepend, or append defines. Some architectures use one
+* some use the other. You need to figure out which ones is
+* right for your situation. I would recommend prepending
+* because it's the safest (i.e. CONFIG_CMDLINE_PREPEND).
+*/
+   BUILD_BUG_ON(sizeof(CONFIG_CMDLINE) != 1);
+
+   if (sizeof(CONFIG_CMDLINE_PREPEND) > 1) {
+   strlcpy(tmp, CONFIG_CMDLINE_PREPEND, length);
+   strlcat(tmp, " ", length);
+   strlcat(tmp, dest, length);
+   strlcpy(dest, tmp, length);
+   }
+}
+
+#define cmdline_add_builtin(dest, src, length) \
+{  \
+   if (sizeof(CONFIG_CMDLINE_PREPEND) > 1) {   \
+   static char cmdline_tmp_space[length] __initdata;   \
+   _cmdline_add_builtin(dest, src, cmdline_tmp_space, length); \
+   } else {\
+   _cmdline_add_builtin(dest, src, NULL, length);  \
+   }   \
+}
+#else
+#define cmdline_add_builtin(dest, src, length)\
+{ \
+   strlcpy(dest, CONFIG_CMDLINE_PREPEND " " CONFIG_CMDLINE_APPEND,\
+   length);   \
+}
+#endif /* !CONFIG_CMDLINE_OVERRIDE */
+
+#else
+#define cmdline_add_builtin(dest, src, length) { \
+   if (src != NULL)   \
+   strlcpy(dest, src, length);\
+}
+#endif /* CONFIG_GENERIC_CMDLINE */
+
+
+#endif /* _LINUX_CMDLINE_H */
diff --git a/init/Kconfig b/init/Kconfig
index a4112e95724a..bac58530e082 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -1775,6 +1775,78 @@ config PROFILING
 config TRACEPOINTS
bool
 
+config GENERIC_CMDLINE
+   bool
+
+if GENERIC_CMDLINE
+
+config CMDLINE_BOOL
+   bool "Built-in kernel command line"
+   help
+ Allow for specifying boot arguments to the kernel at
+ build time.  On some systems (e.g. embedded ones), it is
+ necessary or convenient to provide some or all of the
+ kernel boot arguments with the kernel itself (that is,
+ to not rely on the boot loader to provide them.)
+

[PATCH 3/3] powerpc: convert config files to generic cmdline

2018-11-09 Thread Daniel Walker
This is a scripted mass convert of the config files to use
the new generic cmdline. There is a bit of a trim effect here.
It would seems that some of the config haven't been trimmed in
a while.

The script used to convert is as follows,

if [[ -z "$1" || -z "$2" ]]; then
echo "Two arguments are needed."
exit 1
fi
mkdir $1
cp $2 $1/.config
sed -i 's/CONFIG_CMDLINE=/CONFIG_CMDLINE_PREPEND=/g' $1/.config
make ARCH=$1 O=$1 olddefconfig
make ARCH=$1 O=$1 savedefconfig
cp $1/defconfig $2
rm -Rf $1

Cc: xe-linux-exter...@cisco.com
Cc: Daniel Walker 
Signed-off-by: Daniel Walker 
---
 arch/powerpc/configs/44x/fsp2_defconfig   | 29 
 arch/powerpc/configs/44x/iss476-smp_defconfig | 24 +++---
 arch/powerpc/configs/44x/warp_defconfig   | 12 +++
 arch/powerpc/configs/holly_defconfig  | 12 +++
 arch/powerpc/configs/mvme5100_defconfig   | 25 +++---
 arch/powerpc/configs/skiroot_defconfig| 48 +--
 arch/powerpc/configs/storcenter_defconfig | 15 -
 7 files changed, 80 insertions(+), 85 deletions(-)

diff --git a/arch/powerpc/configs/44x/fsp2_defconfig 
b/arch/powerpc/configs/44x/fsp2_defconfig
index bae6b26bcfba..bafea495c9b8 100644
--- a/arch/powerpc/configs/44x/fsp2_defconfig
+++ b/arch/powerpc/configs/44x/fsp2_defconfig
@@ -1,8 +1,6 @@
-CONFIG_44x=y
 # CONFIG_SWAP is not set
 CONFIG_SYSVIPC=y
 # CONFIG_CROSS_MEMORY_ATTACH is not set
-# CONFIG_FHANDLE is not set
 CONFIG_NO_HZ=y
 CONFIG_HIGH_RES_TIMERS=y
 CONFIG_IKCONFIG=y
@@ -13,25 +11,26 @@ CONFIG_BLK_DEV_INITRD=y
 # CONFIG_RD_XZ is not set
 # CONFIG_RD_LZO is not set
 # CONFIG_RD_LZ4 is not set
+# CONFIG_FHANDLE is not set
 CONFIG_KALLSYMS_ALL=y
 CONFIG_BPF_SYSCALL=y
 CONFIG_EMBEDDED=y
 CONFIG_PROFILING=y
-CONFIG_OPROFILE=y
-CONFIG_MODULES=y
-CONFIG_MODULE_UNLOAD=y
-# CONFIG_BLK_DEV_BSG is not set
+CONFIG_CMDLINE_BOOL=y
+CONFIG_CMDLINE_PREPEND="ip=on rw"
+CONFIG_44x=y
 CONFIG_PPC_47x=y
 # CONFIG_EBONY is not set
 CONFIG_FSP2=y
 CONFIG_476FPE_ERR46=y
-CONFIG_SWIOTLB=y
 CONFIG_KEXEC=y
 CONFIG_CRASH_DUMP=y
-CONFIG_CMDLINE_BOOL=y
-CONFIG_CMDLINE="ip=on rw"
 # CONFIG_SUSPEND is not set
 # CONFIG_PCI is not set
+CONFIG_OPROFILE=y
+CONFIG_MODULES=y
+CONFIG_MODULE_UNLOAD=y
+# CONFIG_BLK_DEV_BSG is not set
 CONFIG_NET=y
 CONFIG_PACKET=y
 CONFIG_UNIX=y
@@ -112,6 +111,12 @@ CONFIG_NFS_V3_ACL=y
 CONFIG_NFS_V4=y
 CONFIG_ROOT_NFS=y
 CONFIG_NLS_DEFAULT="n"
+CONFIG_CRYPTO_CBC=y
+CONFIG_CRYPTO_ECB=y
+CONFIG_CRYPTO_PCBC=y
+CONFIG_CRYPTO_MD5=y
+CONFIG_CRYPTO_DES=y
+# CONFIG_CRYPTO_HW is not set
 CONFIG_XZ_DEC=y
 CONFIG_PRINTK_TIME=y
 CONFIG_MESSAGE_LOGLEVEL_DEFAULT=3
@@ -119,9 +124,3 @@ CONFIG_DYNAMIC_DEBUG=y
 CONFIG_DEBUG_INFO=y
 CONFIG_MAGIC_SYSRQ=y
 CONFIG_DETECT_HUNG_TASK=y
-CONFIG_CRYPTO_CBC=y
-CONFIG_CRYPTO_ECB=y
-CONFIG_CRYPTO_PCBC=y
-CONFIG_CRYPTO_MD5=y
-CONFIG_CRYPTO_DES=y
-# CONFIG_CRYPTO_HW is not set
diff --git a/arch/powerpc/configs/44x/iss476-smp_defconfig 
b/arch/powerpc/configs/44x/iss476-smp_defconfig
index d24bfa6ecd62..775b25178714 100644
--- a/arch/powerpc/configs/44x/iss476-smp_defconfig
+++ b/arch/powerpc/configs/44x/iss476-smp_defconfig
@@ -1,5 +1,3 @@
-CONFIG_44x=y
-CONFIG_SMP=y
 CONFIG_SYSVIPC=y
 CONFIG_POSIX_MQUEUE=y
 CONFIG_LOG_BUF_SHIFT=14
@@ -7,21 +5,23 @@ CONFIG_BLK_DEV_INITRD=y
 CONFIG_EXPERT=y
 CONFIG_KALLSYMS_ALL=y
 CONFIG_PROFILING=y
-CONFIG_OPROFILE=y
-CONFIG_MODULES=y
-CONFIG_MODULE_UNLOAD=y
-# CONFIG_BLK_DEV_BSG is not set
+CONFIG_CMDLINE_BOOL=y
+CONFIG_CMDLINE_PREPEND="root=/dev/issblk0"
+CONFIG_44x=y
+CONFIG_SMP=y
 CONFIG_PPC_47x=y
 # CONFIG_EBONY is not set
 CONFIG_ISS4xx=y
 CONFIG_HZ_100=y
 CONFIG_MATH_EMULATION=y
 CONFIG_IRQ_ALL_CPUS=y
-CONFIG_CMDLINE_BOOL=y
-CONFIG_CMDLINE="root=/dev/issblk0"
 # CONFIG_PCI is not set
 CONFIG_ADVANCED_OPTIONS=y
 CONFIG_DYNAMIC_MEMSTART=y
+CONFIG_OPROFILE=y
+CONFIG_MODULES=y
+CONFIG_MODULE_UNLOAD=y
+# CONFIG_BLK_DEV_BSG is not set
 CONFIG_NET=y
 CONFIG_PACKET=y
 CONFIG_UNIX=y
@@ -62,13 +62,13 @@ CONFIG_PROC_KCORE=y
 CONFIG_TMPFS=y
 CONFIG_CRAMFS=y
 # CONFIG_NETWORK_FILESYSTEMS is not set
-CONFIG_DEBUG_INFO=y
-CONFIG_MAGIC_SYSRQ=y
-CONFIG_DETECT_HUNG_TASK=y
-CONFIG_PPC_EARLY_DEBUG=y
 CONFIG_CRYPTO_CBC=y
 CONFIG_CRYPTO_ECB=y
 CONFIG_CRYPTO_PCBC=y
 CONFIG_CRYPTO_MD5=y
 CONFIG_CRYPTO_DES=y
 # CONFIG_CRYPTO_HW is not set
+CONFIG_DEBUG_INFO=y
+CONFIG_MAGIC_SYSRQ=y
+CONFIG_DETECT_HUNG_TASK=y
+CONFIG_PPC_EARLY_DEBUG=y
diff --git a/arch/powerpc/configs/44x/warp_defconfig 
b/arch/powerpc/configs/44x/warp_defconfig
index 6c02f53271cd..4b76897e323f 100644
--- a/arch/powerpc/configs/44x/warp_defconfig
+++ b/arch/powerpc/configs/44x/warp_defconfig
@@ -1,4 +1,3 @@
-CONFIG_44x=y
 CONFIG_LOCALVERSION="-pika"
 # CONFIG_LOCALVERSION_AUTO is not set
 CONFIG_SYSVIPC=y
@@ -7,16 +6,17 @@ CONFIG_IKCONFIG_PROC=y
 CONFIG_LOG_BUF_SHIFT=14
 CONFIG_BLK_DEV_INITRD=y
 CONFIG_EXPERT=y
-CONFIG_MODULES=y
-CONFIG_MODULE_UNLOAD=y
-# CONFIG_B

[PATCH 2/3] powerpc: convert to generic builtin command line

2018-11-09 Thread Daniel Walker
This updates the powerpc code to use the CONFIG_GENERIC_CMDLINE
option.

[maksym.kok...@globallogic.com: add strlcat to prom_init_check.sh
whitelist]
Cc: Daniel Walker 
Cc: Daniel Walker 
Cc: xe-linux-exter...@cisco.com
Signed-off-by: Daniel Walker 
Signed-off-by: Maksym Kokhan 
---
 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(-)

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 8be31261aec8..6321b2a0b87b 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -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
diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c
index fe758cedb93f..d78b1d6fe1c8 100644
--- a/arch/powerpc/kernel/prom.c
+++ b/arch/powerpc/kernel/prom.c
@@ -34,6 +34,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -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);
diff --git a/arch/powerpc/kernel/prom_init.c b/arch/powerpc/kernel/prom_init.c
index f33ff4163a51..41393da56181 100644
--- a/arch/powerpc/kernel/prom_init.c
+++ b/arch/powerpc/kernel/prom_init.c
@@ -30,6 +30,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -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(prom_cmd_line, NULL, sizeof(prom_cmd_line));
+
prom_printf("command line: %s\n", prom_cmd_line);
 
 #ifdef CONFIG_PPC64
diff --git a/arch/powerpc/kernel/prom_init_check.sh 
b/arch/powerpc/kernel/prom_init_check.sh
index 667df97d2595..ab2acc8d8b5a 100644
--- a/arch/powerpc/kernel/prom_init_check.sh
+++ b/arch/powerpc/kernel/prom_init_check.sh
@@ -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."
-- 
2.14.1



  1   2   3   4   5   6   7   8   9   10   >