Skip to contentSkip to conversation

Fix CMDLINE_EXTEND handling for FDT "bootargs"

PATCH Superseded Will Deacon 6 participants 14 messages Feb 25, 2021 – Mar 3, 2021

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Will Deacon

author maintainer
#0 lore raw

cover Fix CMDLINE_EXTEND handling for FDT "bootargs"

Hi folks,

We recently [1] enabled support for CMDLINE_EXTEND on arm64, however when I started looking at replacing Android's out-of-tree implementation [2] with the upstream version, I noticed that the two behave significantly
differently: Android follows the Kconfig help text of appending the bootloader arguments to the kernel command line, whereas upstream appends the kernel command line to the bootloader arguments. That is, except for the EFI stub, which follows the documented behaviour.

I think the documented behaviour is more useful, so this patch series reworks the FDT code to follow that and updates the very recently merged arm64 idreg early command-line parsing as well.

I'd like to take the first patch as a fix via the arm64 tree.

Cheers,

Will

[1] https://lore.kernel.org/r/[email protected]
[2] https://android-review.googlesource.com/c/kernel/common/+/841045

--->8

Cc Max Uvarov <[email protected]>
Cc Rob Herring <[email protected]>
Cc Ard Biesheuvel <[email protected]>
Cc Marc Zyngier <[email protected]>
Cc Doug Anderson <[email protected]>
Cc Tyler Hicks <[email protected]>
Cc Frank Rowand <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Palmer Dabbelt <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Catalin Marinas <[email protected]>

Will Deacon (2):
arm64: cpufeatures: Fix handling of CONFIG_CMDLINE for idreg overrides of/fdt: Append bootloader arguments when CMDLINE_EXTEND=y

 arch/arm64/kernel/idreg-override.c | 44 +++++++++++---------
 drivers/of/fdt.c                   | 64 ++++++++++++++++++------------
 2 files changed, 64 insertions(+), 44 deletions(-)
Signature · 1 line
2.30.1.766.gb4fecdf3b7-goog
author maintainer
#1 lore raw

PATCH 1/2 arm64: cpufeatures: Fix handling of CONFIG_CMDLINE for idreg overrides

The built-in kernel commandline (CONFIG_CMDLINE) can be configured in three different ways:

1. CMDLINE_FORCE: Use CONFIG_CMDLINE instead of any bootloader args
2. CMDLINE_EXTEND: Append the bootloader args to CONFIG_CMDLINE
3. CMDLINE_FROM_BOOTLOADER: Only use CONFIG_CMDLINE if there aren't any bootloader args.

The early cmdline parsing to detect idreg overrides gets (2) and (3) slightly wrong: in the case of (2) the bootloader args are parsed first and in the case of (3) the CMDLINE is always parsed.

Fix these issues by moving the bootargs parsing out into a helper function and following the same logic as that used by the EFI stub.

Cc Marc Zyngier <[email protected]>
Fixes 33200303553d ("arm64: cpufeature: Add an early command-line cpufeature override facility")
---
 arch/arm64/kernel/idreg-override.c | 44 +++++++++++++++++-------------
 1 file changed, 25 insertions(+), 19 deletions(-)
arch/arm64/kernel/idreg-override.c +25 -19
index dffb16682330..cc071712c6f9 100644
@@ -163,33 +163,39 @@ static __init void __parse_cmdline(const char *cmdline, bool parse_aliases)
 	} while (1);
 }
 
-static __init void parse_cmdline(void)
+static __init const u8 *get_bootargs_cmdline(void)
 {
-	if (!IS_ENABLED(CONFIG_CMDLINE_FORCE)) {
-		const u8 *prop;
-		void *fdt;
-		int node;
+	const u8 *prop;
+	void *fdt;
+	int node;
 
-		fdt = get_early_fdt_ptr();
-		if (!fdt)
-			goto out;
+	fdt = get_early_fdt_ptr();
+	if (!fdt)
+		return NULL;
 
-		node = fdt_path_offset(fdt, "/chosen");
-		if (node < 0)
-			goto out;
+	node = fdt_path_offset(fdt, "/chosen");
+	if (node < 0)
+		return NULL;
 
-		prop = fdt_getprop(fdt, node, "bootargs", NULL);
-		if (!prop)
-			goto out;
+	prop = fdt_getprop(fdt, node, "bootargs", NULL);
+	if (!prop)
+		return NULL;
 
-		__parse_cmdline(prop, true);
+	return strlen(prop) ? prop : NULL;
+}
 
-		if (!IS_ENABLED(CONFIG_CMDLINE_EXTEND))
-			return;
+static __init void parse_cmdline(void)
+{
+	const u8 *prop = get_bootargs_cmdline();
+
+	if (IS_ENABLED(CONFIG_CMDLINE_EXTEND) ||
+	    IS_ENABLED(CONFIG_CMDLINE_FORCE) ||
+	    !prop) {
+		__parse_cmdline(CONFIG_CMDLINE, true);
 	}
 
-out:
-	__parse_cmdline(CONFIG_CMDLINE, true);
+	if (!IS_ENABLED(CONFIG_CMDLINE_FORCE) && prop)
+		__parse_cmdline(prop, true);
 }
 
 /* Keep checkers quiet */
Signature · 1 line
2.30.1.766.gb4fecdf3b7-goog
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] arm64: cpufeatures: Fix handling of CONFIG_CMDLINE for idreg overrides

Quoted 66 lines · Will Deacon

The built-in kernel commandline (CONFIG_CMDLINE) can be configured in three different ways:

1. CMDLINE_FORCE: Use CONFIG_CMDLINE instead of any bootloader args
2. CMDLINE_EXTEND: Append the bootloader args to CONFIG_CMDLINE
3. CMDLINE_FROM_BOOTLOADER: Only use CONFIG_CMDLINE if there aren't any bootloader args.

The early cmdline parsing to detect idreg overrides gets (2) and (3) slightly wrong: in the case of (2) the bootloader args are parsed first and in the case of (3) the CMDLINE is always parsed.

Fix these issues by moving the bootargs parsing out into a helper function and following the same logic as that used by the EFI stub.

Cc Marc Zyngier <[email protected]>
Fixes 33200303553d ("arm64: cpufeature: Add an early command-line cpufeature override facility")
---
 arch/arm64/kernel/idreg-override.c | 44 +++++++++++++++++-------------
 1 file changed, 25 insertions(+), 19 deletions(-)
arch/arm64/kernel/idreg-override.c +15 -15
index dffb16682330..cc071712c6f9 100644
@@ -163,33 +163,39 @@ static __init void __parse_cmdline(const char *cmdline, bool parse_aliases)
 	} while (1);
 }
 
-static __init void parse_cmdline(void)
+static __init const u8 *get_bootargs_cmdline(void)
 {
-	if (!IS_ENABLED(CONFIG_CMDLINE_FORCE)) {
-		const u8 *prop;
-		void *fdt;
-		int node;
+	const u8 *prop;
+	void *fdt;
+	int node;
 
-		fdt = get_early_fdt_ptr();
-		if (!fdt)
-			goto out;
+	fdt = get_early_fdt_ptr();
+	if (!fdt)
+		return NULL;
 
-		node = fdt_path_offset(fdt, "/chosen");
-		if (node < 0)
-			goto out;
+	node = fdt_path_offset(fdt, "/chosen");
+	if (node < 0)
+		return NULL;
 
-		prop = fdt_getprop(fdt, node, "bootargs", NULL);
-		if (!prop)
-			goto out;
+	prop = fdt_getprop(fdt, node, "bootargs", NULL);
+	if (!prop)
+		return NULL;
 
-		__parse_cmdline(prop, true);
+	return strlen(prop) ? prop : NULL;
+}

arch/arm64/kernel/idreg-override.c static __init void __parse_cmdline(const char *cmdline, bool parse_aliases) · line 193

Quoted 10 lines
arch/arm64/kernel/idreg-override.c +7 -2
 
-		if (!IS_ENABLED(CONFIG_CMDLINE_EXTEND))
-			return;
+static __init void parse_cmdline(void)
+{
+	const u8 *prop = get_bootargs_cmdline();
+
+	if (IS_ENABLED(CONFIG_CMDLINE_EXTEND) ||
+	    IS_ENABLED(CONFIG_CMDLINE_FORCE) ||
+	    !prop) {

The logic hurts, but I think I grok it now. The last term is actually a reduction of

	(IS_ENABLED(CONFIG_CMDLINE_FROM_BOOTLOADER) && !prop)

and we know for sure that if none of the other two terms are true, then CMDLINE_FROM_BOOTLOADER *must* be enabled.

arch/arm64/kernel/idreg-override.c static __init void __parse_cmdline(const char *cmdline, bool parse_aliases) · line 201

Quoted 10 lines
arch/arm64/kernel/idreg-override.c +3 -2
+		__parse_cmdline(CONFIG_CMDLINE, true);
 	}
 
-out:
-	__parse_cmdline(CONFIG_CMDLINE, true);
+	if (!IS_ENABLED(CONFIG_CMDLINE_FORCE) && prop)
+		__parse_cmdline(prop, true);
 }
 
 /* Keep checkers quiet */

I don't think we need to backport anything to stable for the nokaslr handling, do we?

Otherwise,

Thanks,

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
author maintainer
#3 lore raw

Re: [PATCH 1/2] arm64: cpufeatures: Fix handling of CONFIG_CMDLINE for idreg overrides

Quoted 82 lines · Marc Zyngier
Quoted 66 lines · Will Deacon

The built-in kernel commandline (CONFIG_CMDLINE) can be configured in three different ways:

1. CMDLINE_FORCE: Use CONFIG_CMDLINE instead of any bootloader args
2. CMDLINE_EXTEND: Append the bootloader args to CONFIG_CMDLINE
3. CMDLINE_FROM_BOOTLOADER: Only use CONFIG_CMDLINE if there aren't any bootloader args.

The early cmdline parsing to detect idreg overrides gets (2) and (3) slightly wrong: in the case of (2) the bootloader args are parsed first and in the case of (3) the CMDLINE is always parsed.

Fix these issues by moving the bootargs parsing out into a helper function and following the same logic as that used by the EFI stub.

Cc Marc Zyngier <[email protected]>
Fixes 33200303553d ("arm64: cpufeature: Add an early command-line cpufeature override facility")
---
 arch/arm64/kernel/idreg-override.c | 44 +++++++++++++++++-------------
 1 file changed, 25 insertions(+), 19 deletions(-)
arch/arm64/kernel/idreg-override.c +15 -15
index dffb16682330..cc071712c6f9 100644
@@ -163,33 +163,39 @@ static __init void __parse_cmdline(const char *cmdline, bool parse_aliases)
 	} while (1);
 }
 
-static __init void parse_cmdline(void)
+static __init const u8 *get_bootargs_cmdline(void)
 {
-	if (!IS_ENABLED(CONFIG_CMDLINE_FORCE)) {
-		const u8 *prop;
-		void *fdt;
-		int node;
+	const u8 *prop;
+	void *fdt;
+	int node;
 
-		fdt = get_early_fdt_ptr();
-		if (!fdt)
-			goto out;
+	fdt = get_early_fdt_ptr();
+	if (!fdt)
+		return NULL;
 
-		node = fdt_path_offset(fdt, "/chosen");
-		if (node < 0)
-			goto out;
+	node = fdt_path_offset(fdt, "/chosen");
+	if (node < 0)
+		return NULL;
 
-		prop = fdt_getprop(fdt, node, "bootargs", NULL);
-		if (!prop)
-			goto out;
+	prop = fdt_getprop(fdt, node, "bootargs", NULL);
+	if (!prop)
+		return NULL;
 
-		__parse_cmdline(prop, true);
+	return strlen(prop) ? prop : NULL;
+}

arch/arm64/kernel/idreg-override.c static __init void __parse_cmdline(const char *cmdline, bool parse_aliases) · line 193

Quoted 10 lines
arch/arm64/kernel/idreg-override.c +7 -2
 
-		if (!IS_ENABLED(CONFIG_CMDLINE_EXTEND))
-			return;
+static __init void parse_cmdline(void)
+{
+	const u8 *prop = get_bootargs_cmdline();
+
+	if (IS_ENABLED(CONFIG_CMDLINE_EXTEND) ||
+	    IS_ENABLED(CONFIG_CMDLINE_FORCE) ||
+	    !prop) {

The logic hurts, but I think I grok it now. The last term is actually a reduction of

Quoted 4 lines
	(IS_ENABLED(CONFIG_CMDLINE_FROM_BOOTLOADER) && !prop)

and we know for sure that if none of the other two terms are true, then CMDLINE_FROM_BOOTLOADER *must* be enabled.

Yes, with one gotcha: when CONFIG_CMDLINE is "", I don't think any of the CONFIG_CMDLINE_* are set, but the behaviour ends up being the same as CMDLINE_FROM_BOOTLOADER.

Quoted 10 lines
Quoted 10 lines
arch/arm64/kernel/idreg-override.c +3 -2
+		__parse_cmdline(CONFIG_CMDLINE, true);
 	}
 
-out:
-	__parse_cmdline(CONFIG_CMDLINE, true);
+	if (!IS_ENABLED(CONFIG_CMDLINE_FORCE) && prop)
+		__parse_cmdline(prop, true);
 }
 
Quoted 4 lines

arch/arm64/kernel/idreg-override.c static __init void __parse_cmdline(const char *cmdline, bool parse_aliases) · line 201

Quoted 1 line
arch/arm64/kernel/idreg-override.c +0 -0
 /* Keep checkers quiet */

I don't think we need to backport anything to stable for the nokaslr handling, do we?

No, I don't think so. There isn't a "kaslr" or "nonokaslr", so the ordering doesn't matter afaict.

Quoted 1 line

Cheers!

Will

author maintainer
#4 lore raw

PATCH 2/2 of/fdt: Append bootloader arguments when CMDLINE_EXTEND=y

In reply to Will Deacon

The Kconfig help text for CMDLINE_EXTEND is sadly duplicated across all architectures that implement it (arm, arm64, powerpc, riscv and sh), but they all seem to agree that the bootloader arguments will be appended to the CONFIG_CMDLINE. For example, on arm64:

| The command-line arguments provided by the boot loader will be | appended to the default kernel command string.

This also matches the behaviour of the EFI stub, which parses the bootloader arguments first if CMDLINE_EXTEND is set, as well as the out-of-tree CMDLINE_EXTEND implementation in Android.

However, the behaviour in the upstream fdt code appears to be the other way around: CONFIG_CMDLINE is appended to the bootloader arguments.

Fix the code to follow the documentation by moving the cmdline processing out into a new function, early_init_dt_retrieve_cmdline(), and copying CONFIG_CMDLINE to the beginning of the cmdline buffer rather than concatenating it onto the end.

Cc Max Uvarov <[email protected]>
Cc Rob Herring <[email protected]>
Cc Ard Biesheuvel <[email protected]>
Cc Marc Zyngier <[email protected]>
Cc Doug Anderson <[email protected]>
Cc Tyler Hicks <[email protected]>
Cc Frank Rowand <[email protected]>
Fixes 34b82026a507 ("fdt: fix extend of cmd line")
---
 drivers/of/fdt.c | 64 +++++++++++++++++++++++++++++-------------------
 1 file changed, 39 insertions(+), 25 deletions(-)
drivers/of/fdt.c +39 -25
index dcc1dd96911a..83b9d065e58d 100644
@@ -1033,11 +1033,48 @@ int __init early_init_dt_scan_memory(unsigned long node, const char *uname,
 	return 0;
 }
 
+static int __init cmdline_from_bootargs(unsigned long node, void *dst, int sz)
+{
+	int l;
+	const char *p = of_get_flat_dt_prop(node, "bootargs", &l);
+
+	if (!p || l <= 0)
+		return -EINVAL;
+
+	return strlcpy(dst, p, min(l, sz));
+}
+
+/* dst is a zero-initialised buffer of COMMAND_LINE_SIZE bytes */
+static void __init early_init_dt_retrieve_cmdline(unsigned long node, char *dst)
+{
+	if (IS_ENABLED(CONFIG_CMDLINE_EXTEND)) {
+		/* Copy CONFIG_CMDLINE to the start of destination buffer */
+		size_t idx = strlcpy(dst, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
+
+		/* Check that we have enough space to concatenate */
+		if (idx + 1 >= COMMAND_LINE_SIZE)
+			return;
+
+		/* Append the bootloader arguments */
+		dst[idx++] = ' ';
+		cmdline_from_bootargs(node, &dst[idx], COMMAND_LINE_SIZE - idx);
+	} else if (IS_ENABLED(CONFIG_CMDLINE_FORCE)) {
+		/* Just use CONFIG_CMDLINE */
+		strlcpy(dst, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
+	} else if (IS_ENABLED(CONFIG_CMDLINE_FROM_BOOTLOADER)) {
+		/* Use CONFIG_CMDLINE if no arguments from bootloader. */
+		if (cmdline_from_bootargs(node, dst, COMMAND_LINE_SIZE) <= 0)
+			strlcpy(dst, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
+	} else {
+		/* Just use bootloader arguments */
+		cmdline_from_bootargs(node, dst, COMMAND_LINE_SIZE);
+	}
+}
+
 int __init early_init_dt_scan_chosen(unsigned long node, const char *uname,
 				     int depth, void *data)
 {
 	int l;
-	const char *p;
 	const void *rng_seed;
 
 	pr_debug("search \"chosen\", depth: %d, uname: %s\n", depth, uname);
@@ -1047,30 +1084,7 @@ int __init early_init_dt_scan_chosen(unsigned long node, const char *uname,
 		return 0;
 
 	early_init_dt_check_for_initrd(node);
-
-	/* Retrieve command line */
-	p = of_get_flat_dt_prop(node, "bootargs", &l);
-	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.
-	 */
-#ifdef CONFIG_CMDLINE
-#if defined(CONFIG_CMDLINE_EXTEND)
-	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);
-#endif
-#endif /* CONFIG_CMDLINE */
-
+	early_init_dt_retrieve_cmdline(node, data);
 	pr_debug("Command line is: %s\n", (char *)data);
 
 	rng_seed = of_get_flat_dt_prop(node, "rng-seed", &l);
Signature · 1 line
2.30.1.766.gb4fecdf3b7-goog
Reviewed-by on v1 2/2
#5 lore raw

Re: [PATCH 2/2] of/fdt: Append bootloader arguments when CMDLINE_EXTEND=y

Quoted 65 lines · Will Deacon

The Kconfig help text for CMDLINE_EXTEND is sadly duplicated across all architectures that implement it (arm, arm64, powerpc, riscv and sh), but they all seem to agree that the bootloader arguments will be appended to the CONFIG_CMDLINE. For example, on arm64:

| The command-line arguments provided by the boot loader will be | appended to the default kernel command string.

This also matches the behaviour of the EFI stub, which parses the bootloader arguments first if CMDLINE_EXTEND is set, as well as the out-of-tree CMDLINE_EXTEND implementation in Android.

However, the behaviour in the upstream fdt code appears to be the other way around: CONFIG_CMDLINE is appended to the bootloader arguments.

Fix the code to follow the documentation by moving the cmdline processing out into a new function, early_init_dt_retrieve_cmdline(), and copying CONFIG_CMDLINE to the beginning of the cmdline buffer rather than concatenating it onto the end.

Cc Max Uvarov <[email protected]>
Cc Rob Herring <[email protected]>
Cc Ard Biesheuvel <[email protected]>
Cc Marc Zyngier <[email protected]>
Cc Doug Anderson <[email protected]>
Cc Tyler Hicks <[email protected]>
Cc Frank Rowand <[email protected]>
Fixes 34b82026a507 ("fdt: fix extend of cmd line")
---
 drivers/of/fdt.c | 64 +++++++++++++++++++++++++++++-------------------
 1 file changed, 39 insertions(+), 25 deletions(-)
drivers/of/fdt.c +23 -0
index dcc1dd96911a..83b9d065e58d 100644
@@ -1033,11 +1033,48 @@ int __init early_init_dt_scan_memory(unsigned long node, const char *uname,
 	return 0;
 }
 
+static int __init cmdline_from_bootargs(unsigned long node, void *dst, int sz)
+{
+	int l;
+	const char *p = of_get_flat_dt_prop(node, "bootargs", &l);
+
+	if (!p || l <= 0)
+		return -EINVAL;
+
+	return strlcpy(dst, p, min(l, sz));
+}
+
+/* dst is a zero-initialised buffer of COMMAND_LINE_SIZE bytes */
+static void __init early_init_dt_retrieve_cmdline(unsigned long node, char *dst)
+{
+	if (IS_ENABLED(CONFIG_CMDLINE_EXTEND)) {
+		/* Copy CONFIG_CMDLINE to the start of destination buffer */
+		size_t idx = strlcpy(dst, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
+
+		/* Check that we have enough space to concatenate */
+		if (idx + 1 >= COMMAND_LINE_SIZE)
+			return;
+
+		/* Append the bootloader arguments */

drivers/of/fdt.c int __init early_init_dt_scan_memory(unsigned long node, const char *uname, · line 1068

Quoted 10 lines
drivers/of/fdt.c +10 -0
+		dst[idx++] = ' ';
+		cmdline_from_bootargs(node, &dst[idx], COMMAND_LINE_SIZE - idx);
+	} else if (IS_ENABLED(CONFIG_CMDLINE_FORCE)) {
+		/* Just use CONFIG_CMDLINE */
+		strlcpy(dst, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
+	} else if (IS_ENABLED(CONFIG_CMDLINE_FROM_BOOTLOADER)) {
+		/* Use CONFIG_CMDLINE if no arguments from bootloader. */
+		if (cmdline_from_bootargs(node, dst, COMMAND_LINE_SIZE) <= 0)
+			strlcpy(dst, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
+	} else {

Do we have any arch that can end-up not defining any of the 3 above cases? We should be able to just have the above case as the catch-all, and drop the one below.

Quoted 49 lines
drivers/of/fdt.c +6 -25
+		/* Just use bootloader arguments */
+		cmdline_from_bootargs(node, dst, COMMAND_LINE_SIZE);
+	}
+}
+
 int __init early_init_dt_scan_chosen(unsigned long node, const char *uname,
 				     int depth, void *data)
 {
 	int l;
-	const char *p;
 	const void *rng_seed;
 
 	pr_debug("search \"chosen\", depth: %d, uname: %s\n", depth, uname);
@@ -1047,30 +1084,7 @@ int __init early_init_dt_scan_chosen(unsigned long node, const char *uname,
 		return 0;
 
 	early_init_dt_check_for_initrd(node);
-
-	/* Retrieve command line */
-	p = of_get_flat_dt_prop(node, "bootargs", &l);
-	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.
-	 */
-#ifdef CONFIG_CMDLINE
-#if defined(CONFIG_CMDLINE_EXTEND)
-	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);
-#endif
-#endif /* CONFIG_CMDLINE */
-
+	early_init_dt_retrieve_cmdline(node, data);
 	pr_debug("Command line is: %s\n", (char *)data);
 
 	rng_seed = of_get_flat_dt_prop(node, "rng-seed", &l);
Signature · 1 line
2.30.1.766.gb4fecdf3b7-goog

Other than the above nit:

Thanks,

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
#6 lore raw

Re: [PATCH 2/2] of/fdt: Append bootloader arguments when CMDLINE_EXTEND=y

In reply to Will Deacon
I love your patch! Yet something to improve:

Hi Will,

I love your patch! Yet something to improve:

[auto build test ERROR on arm64/for-next/core]
[also build test ERROR on linus/master v5.12-rc1 next-20210303] [cannot apply to robh/for-next linux/master]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Will-Deacon/Fix-CMDLINE_EXTEND-handling-for-FDT-bootargs/20210225-210308
base:   https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-next/core
config: h8300-randconfig-r001-20210303 (attached as .config)
compiler: h8300-linux-gcc (GCC) 9.3.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/4a51ebf041dde84115b1c49a9fbca337791a66fc
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Will-Deacon/Fix-CMDLINE_EXTEND-handling-for-FDT-bootargs/20210225-210308 git checkout 4a51ebf041dde84115b1c49a9fbca337791a66fc
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=h8300

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>):

drivers/of/fdt.c: In function 'early_init_dt_retrieve_cmdline':

>> drivers/of/fdt.c:1052:29: error: 'CONFIG_CMDLINE' undeclared (first use in this function); did you mean 'CONFIG_FB_CMDLINE'?
    1052 |   size_t idx = strlcpy(dst, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
         |                             ^~~~~~~~~~~~~~
         |                             CONFIG_FB_CMDLINE

drivers/of/fdt.c:1052:29: note: each undeclared identifier is reported only once for each function it appears in

vim +1052 drivers/of/fdt.c

1046
1047 /* dst is a zero-initialised buffer of COMMAND_LINE_SIZE bytes */
1048 static void __init early_init_dt_retrieve_cmdline(unsigned long node, char *dst)
1049 {
1050 if (IS_ENABLED(CONFIG_CMDLINE_EXTEND)) {
1051 /* Copy CONFIG_CMDLINE to the start of destination buffer */

> 1052			size_t idx = strlcpy(dst, CONFIG_CMDLINE, COMMAND_LINE_SIZE);

1053
1054 /* Check that we have enough space to concatenate */
1055 if (idx + 1 >= COMMAND_LINE_SIZE)
1056 return;
1057
1058 /* Append the bootloader arguments */
1059 dst[idx++] = ' ';
1060 cmdline_from_bootargs(node, &dst[idx], COMMAND_LINE_SIZE - idx);
1061 } else if (IS_ENABLED(CONFIG_CMDLINE_FORCE)) {
1062 /* Just use CONFIG_CMDLINE */
1063 strlcpy(dst, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
1064 } else if (IS_ENABLED(CONFIG_CMDLINE_FROM_BOOTLOADER)) {
1065 /* Use CONFIG_CMDLINE if no arguments from bootloader. */
1066 if (cmdline_from_bootargs(node, dst, COMMAND_LINE_SIZE) <= 0)
1067 strlcpy(dst, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
1068 } else {
1069 /* Just use bootloader arguments */
1070 cmdline_from_bootargs(node, dst, COMMAND_LINE_SIZE);
1071 }
1072 }
1073

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]

maintainer
#7 lore raw
In reply to Will Deacon
Quoted 5 lines · Will Deacon

Hi folks,

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.

Quoted 9 lines

with the upstream version, I noticed that the two behave significantly
differently: Android follows the Kconfig help text of appending the bootloader arguments to the kernel command line, whereas upstream appends the kernel command line to the bootloader arguments. That is, except for the EFI stub, which follows the documented behaviour.

I think the documented behaviour is more useful, so this patch series reworks the FDT code to follow that and updates the very recently merged arm64 idreg early command-line parsing as well.

I can just as easily argue that the kernel having the last say makes sense. Regardless, I'm pretty sure there's someone out there relying on current behavior. What is the impact of this change to other arches?

Rob

[1] https://lore.kernel.org/lkml/[email protected]/

author maintainer
#8 lore raw
Quoted 8 lines · Rob Herring
Quoted 2 lines · Will Deacon

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.

Quoted 6 lines
Quoted 6 lines

with the upstream version, I noticed that the two behave significantly
differently: Android follows the Kconfig help text of appending the bootloader arguments to the kernel command line, whereas upstream appends the kernel command line to the bootloader arguments. That is, except for the EFI stub, which follows the documented behaviour.

Quoted 6 lines
Quoted 3 lines

I think the documented behaviour is more useful, so this patch series reworks the FDT code to follow that and updates the very recently merged arm64 idreg early command-line parsing as well.

I can just as easily argue that the kernel having the last say makes sense.

Dunno, I'd say that's what CMDLINE_FORCE is for. Plus you'd be arguing against both the documentation and the EFI stub implementation.

Quoted 2 lines

Regardless, I'm pretty sure there's someone out there relying on current behavior. What is the impact of this change to other arches?

On arm64, I doubt it, as Android is the main user of this (where it's been supported for 9 years with the documented behaviour).

The other option, then, is reverting CMDLINE_EXTEND from arm64 until this is figured out. I think that's preferable to having divergent behaviour.

As for other architectures, I think the ATAGs-based solution on arch/arm/ gets it right:

  static int __init parse_tag_cmdline(const struct tag *tag)
  {
  #if defined(CONFIG_CMDLINE_EXTEND)
          strlcat(default_command_line, " ", COMMAND_LINE_SIZE);
          strlcat(default_command_line, tag->u.cmdline.cmdline,
                  COMMAND_LINE_SIZE);

For now I think we have two options for arm64: either fix the fdt code, or revert CMDLINE_EXTEND until the PREPEND/APPEND series is merged. Which do you prefer?

Will

maintainer
#9 lore raw

+PPC folks and Daniel W

Quoted 11 lines · Will Deacon
Quoted 8 lines · Rob Herring
Quoted 2 lines · Will Deacon

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.

Quoted 4 lines

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/[email protected]/
https://lore.kernel.org/linuxppc-dev/[email protected]/
https://lore.kernel.org/linuxppc-dev/[email protected]/

(Once again, there's some weird threading going on)

Quoted 10 lines
Quoted 10 lines
Quoted 9 lines

with the upstream version, I noticed that the two behave significantly
differently: Android follows the Kconfig help text of appending the bootloader arguments to the kernel command line, whereas upstream appends the kernel command line to the bootloader arguments. That is, except for the EFI stub, which follows the documented behaviour.

I think the documented behaviour is more useful, so this patch series reworks the FDT code to follow that and updates the very recently merged arm64 idreg early command-line parsing as well.

Quoted 5 lines
Quoted 2 lines

I can just as easily argue that the kernel having the last say makes sense.

Dunno, I'd say that's what CMDLINE_FORCE is for. Plus you'd be arguing against both the documentation and the EFI stub implementation.

CMDLINE_FORCE is a complete override, not a merging of command lines.

Quoted 12 lines
Quoted 2 lines

Regardless, I'm pretty sure there's someone out there relying on current behavior. What is the impact of this change to other arches?

On arm64, I doubt it, as Android is the main user of this (where it's been supported for 9 years with the documented behaviour).

The other option, then, is reverting CMDLINE_EXTEND from arm64 until this is figured out. I think that's preferable to having divergent behaviour.

As for other architectures, I think the ATAGs-based solution on arch/arm/ gets it right:

Quoted 6 lines
  static int __init parse_tag_cmdline(const struct tag *tag)
  {
  #if defined(CONFIG_CMDLINE_EXTEND)
          strlcat(default_command_line, " ", COMMAND_LINE_SIZE);
          strlcat(default_command_line, tag->u.cmdline.cmdline,
                  COMMAND_LINE_SIZE);

The question is really whether any arm32 DT based platform depends on the current behavior. RiscV could also be relying on current behavior. Powerpc also uses the current behavior (and the documentation is also wrong there). Changing the behavior in the FDT code means the powerpc early PROM code and the FDT code do the opposite.

Arm32 has had current behaviour for 5 years. Powerpc for 1.5 years and Risc-V for 2 years. Then there's MIPS which has its own Kconfig symbols for this and is its own kind of mess. Either we assume existing users didn't really care about the order or we have to support both prepend and append.

Quoted 3 lines

For now I think we have two options for arm64: either fix the fdt code, or revert CMDLINE_EXTEND until the PREPEND/APPEND series is merged. Which do you prefer?

Like anything copied across arches, I want someone to look at this across all architectures and make this common instead of just copying to new arches. The prepend/append series is the closest we've come.

Rob

#10 lore raw

Le 01/03/2021 à 18:26, Rob Herring a écrit :

Quoted 19 lines

+PPC folks and Daniel W

Quoted 11 lines · Will Deacon
Quoted 8 lines · Rob Herring
Quoted 2 lines · Will Deacon

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.

Quoted 4 lines

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.

Quoted 5 lines

Actually, there is a newer version I found:

https://lore.kernel.org/linuxppc-dev/[email protected]/
https://lore.kernel.org/linuxppc-dev/[email protected]/
https://lore.kernel.org/linuxppc-dev/[email protected]/

This was seen as too much intrusive into powerpc.

I proposed an alternative at https://patchwork.ozlabs.org/project/linuxppc-dev/cover/[email protected]/ but never got any feedback.

Quoted 56 lines

(Once again, there's some weird threading going on)

Quoted 10 lines
Quoted 10 lines
Quoted 9 lines

with the upstream version, I noticed that the two behave significantly
differently: Android follows the Kconfig help text of appending the bootloader arguments to the kernel command line, whereas upstream appends the kernel command line to the bootloader arguments. That is, except for the EFI stub, which follows the documented behaviour.

I think the documented behaviour is more useful, so this patch series reworks the FDT code to follow that and updates the very recently merged arm64 idreg early command-line parsing as well.

Quoted 5 lines
Quoted 2 lines

I can just as easily argue that the kernel having the last say makes sense.

Dunno, I'd say that's what CMDLINE_FORCE is for. Plus you'd be arguing against both the documentation and the EFI stub implementation.

CMDLINE_FORCE is a complete override, not a merging of command lines.

Quoted 12 lines
Quoted 2 lines

Regardless, I'm pretty sure there's someone out there relying on current behavior. What is the impact of this change to other arches?

On arm64, I doubt it, as Android is the main user of this (where it's been supported for 9 years with the documented behaviour).

The other option, then, is reverting CMDLINE_EXTEND from arm64 until this is figured out. I think that's preferable to having divergent behaviour.

As for other architectures, I think the ATAGs-based solution on arch/arm/ gets it right:

Quoted 6 lines
   static int __init parse_tag_cmdline(const struct tag *tag)
   {
   #if defined(CONFIG_CMDLINE_EXTEND)
           strlcat(default_command_line, " ", COMMAND_LINE_SIZE);
           strlcat(default_command_line, tag->u.cmdline.cmdline,
                   COMMAND_LINE_SIZE);

The question is really whether any arm32 DT based platform depends on the current behavior. RiscV could also be relying on current behavior. Powerpc also uses the current behavior (and the documentation is also wrong there). Changing the behavior in the FDT code means the powerpc early PROM code and the FDT code do the opposite.

Arm32 has had current behaviour for 5 years. Powerpc for 1.5 years and Risc-V for 2 years. Then there's MIPS which has its own Kconfig symbols for this and is its own kind of mess. Either we assume existing users didn't really care about the order or we have to support both prepend and append.

Quoted 3 lines

For now I think we have two options for arm64: either fix the fdt code, or revert CMDLINE_EXTEND until the PREPEND/APPEND series is merged. Which do you prefer?

Quoted 6 lines

Like anything copied across arches, I want someone to look at this across all architectures and make this common instead of just copying to new arches. The prepend/append series is the closest we've come.

Rob

Christophe

maintainer
#11 lore raw
Quoted 23 lines · Christophe Leroy
Quoted 19 lines · Rob Herring

+PPC folks and Daniel W

Quoted 15 lines · Will Deacon
Quoted 8 lines · Rob Herring
Quoted 2 lines · Will Deacon

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.

Quoted 7 lines
Quoted 5 lines

Actually, there is a newer version I found:

https://lore.kernel.org/linuxppc-dev/[email protected]/
https://lore.kernel.org/linuxppc-dev/[email protected]/
https://lore.kernel.org/linuxppc-dev/[email protected]/

This was seen as too much intrusive into powerpc.

It looked like the main issue was string functions for KASAN?

As far as being too complex, I think that will be needed if you look at all architectures and non-DT cases.

Quoted 3 lines

I proposed an alternative at
https://patchwork.ozlabs.org/project/linuxppc-dev/cover/[email protected]/ but never got any feedback.

Didn't go to a list I subscribe to. In particular, if it had gone to DT list and into PW you would have gotten a reply from me.

Rob

#12 lore raw

Le 02/03/2021 à 15:56, Rob Herring a écrit :

Quoted 27 lines
Quoted 25 lines · Christophe Leroy
Quoted 21 lines · Rob Herring

+PPC folks and Daniel W

Quoted 11 lines · Will Deacon
Quoted 8 lines · Rob Herring
Quoted 2 lines · Will Deacon

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.

Quoted 4 lines

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:

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

https://lore.kernel.org/linuxppc-dev/[email protected]/
https://lore.kernel.org/linuxppc-dev/[email protected]/
https://lore.kernel.org/linuxppc-dev/[email protected]/

This was seen as too much intrusive into powerpc.

It looked like the main issue was string functions for KASAN?

This is one issue yes,

Quoted 3 lines

As far as being too complex, I think that will be needed if you look at all architectures and non-DT cases.

As far as I remember, I could't understand why we absolutely need to define the command line string in the common part of the code, leading to being obliged to use macros in order to allow the architecture to specify in which section it wants the string.

Why not leave the definition of the string to the architecture and just declare it in the common code, allowing the architecture to put it where it suits it and reducing opacity and allowing use of standard static inline functions instead of uggly macros.

Quoted 8 lines
Quoted 4 lines

I proposed an alternative at
https://patchwork.ozlabs.org/project/linuxppc-dev/cover/[email protected]/ but never got any feedback.

Didn't go to a list I subscribe to. In particular, if it had gone to DT list and into PW you would have gotten a reply from me.

Sorry for that. Original series from Daniel (https://patchwork.ozlabs.org/project/linuxppc-dev/patch/[email protected]/) was sent only to linuxppc-dev list, and Michael suggested to also send it to linux-arch list, and I also always copy linux-kernel.

If there is new interest for that functionnality, I can try and rebase my series.

Christophe

#13 lore raw
In reply to Rob Herring
Quoted 19 lines · Rob Herring

+PPC folks and Daniel W

Quoted 11 lines · Will Deacon
Quoted 8 lines · Rob Herring
Quoted 2 lines · Will Deacon

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.

Quoted 4 lines

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.

Quoted 8 lines

Actually, there is a newer version I found:

https://lore.kernel.org/linuxppc-dev/[email protected]/
https://lore.kernel.org/linuxppc-dev/[email protected]/
https://lore.kernel.org/linuxppc-dev/[email protected]/

(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