Skip to contentSkip to conversation

bootconfig: Cleanup and reorder the init parameter from bootconfig

PATCH Superseded Masami Hiramatsu 2 participants 7 messages Aug 26, 2021

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Masami Hiramatsu

author maintainer
#0 lore raw

cover bootconfig: Cleanup and reorder the init parameter from bootconfig

Hi,

Here are some patches to update the bootconfig. The 1st one is for bootconfig memory cleanup when exiting init stage. The 2nd one and 3rd one are for reordering the init parameters from bootconfig. Since the current kernel concatenate the kernel cmdline and the bootconfig parameters as below.

[bootconfig kernel params][cmdline] -- [init cmdline][bootconfig init params]

This is bit odd because for the kernel parameters, user passed cmdline can override the previous (bootconfig) one, but for the init cmdline, bootconfig may override the parameter.
Thus, this series invert the order as the following.

[bootconfig kernel params][cmdline] -- [bootconfig init params][init cmdline]

The 3rd patch is adding how to use the bootconfig for passing kernel and init parameters.

Thank you,

---

Masami Hiramatsu (3):
init: bootconfig: Remove all bootconfig data when the init memory is removed init/bootconfig: Reorder init parameter from bootconfig and cmdline
docs: bootconfig: Add how to use bootconfig for kernel parameters

 Documentation/admin-guide/bootconfig.rst |   39 +++++++++++++++++++++++++++++-
 init/main.c                              |   24 ++++++++++++------
 2 files changed, 53 insertions(+), 10 deletions(-)

--
Masami Hiramatsu (Linaro) <[email protected]>

author maintainer
#1 lore raw

PATCH 1/3 init: bootconfig: Remove all bootconfig data when the init memory is removed

Since the bootconfig is used only in the init functions, it doesn't need to keep the data after boot. Free it when the init memory is removed.

---
 init/main.c |    1 +
 1 file changed, 1 insertion(+)
init/main.c +1 -0
index 8d97aba78c3a..d9b0a99bb2dd 100644
@@ -1493,6 +1493,7 @@ static int __ref kernel_init(void *unused)
 	kprobe_free_init_mem();
 	ftrace_free_init_mem();
 	kgdb_free_init_mem();
+	xbc_destroy_all();
 	free_initmem();
 	mark_readonly();
 
author maintainer
#5 lore raw

PATCH 2/3 init/bootconfig: Reorder init parameter from bootconfig and cmdline

In reply to Masami Hiramatsu

Reorder the init parameters from bootconfig and kernel cmdline so that the kernel cmdline always be the last part of the parameters as below.

" -- "[bootconfig init params][cmdline init params]

This change will help us to prevent that bootconfig init params overwrite the init params which user gives in the command line.

---
 init/main.c |   23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)
init/main.c +14 -9
index d9b0a99bb2dd..b24a18aebed7 100644
@@ -153,10 +153,10 @@ static char *extra_init_args;
 #ifdef CONFIG_BOOT_CONFIG
 /* Is bootconfig on command line? */
 static bool bootconfig_found;
-static bool initargs_found;
+static size_t initargs_offs;
 #else
 # define bootconfig_found false
-# define initargs_found false
+# define initargs_offs 0
 #endif
 
 static char *execute_command;
@@ -422,9 +422,9 @@ static void __init setup_boot_config(void)
 	if (IS_ERR(err) || !bootconfig_found)
 		return;
 
-	/* parse_args() stops at '--' and returns an address */
+	/* parse_args() stops at the next param of '--' and returns an address */
 	if (err)
-		initargs_found = true;
+		initargs_offs = err - tmp_cmdline;
 
 	if (!data) {
 		pr_err("'bootconfig' found on command line, but no bootconfig found\n");
@@ -646,16 +646,21 @@ static void __init setup_command_line(char *command_line)
 		 * Append supplemental init boot args to saved_command_line
 		 * so that user can check what command line options passed
 		 * to init.
+		 * The order should always be
+		 * " -- "[bootconfig init-param][cmdline init-param]
 		 */
-		len = strlen(saved_command_line);
-		if (initargs_found) {
-			saved_command_line[len++] = ' ';
+		if (initargs_offs) {
+			len = xlen + initargs_offs;
+			strcpy(saved_command_line + len, extra_init_args);
+			len += ilen - 4;	/* strlen(extra_init_args) */
+			strcpy(saved_command_line + len,
+				boot_command_line + initargs_offs - 1);
 		} else {
+			len = strlen(saved_command_line);
 			strcpy(saved_command_line + len, " -- ");
 			len += 4;
+			strcpy(saved_command_line + len, extra_init_args);
 		}
-
-		strcpy(saved_command_line + len, extra_init_args);
 	}
 }
 
author maintainer
#6 lore raw

PATCH 3/3 docs: bootconfig: Add how to use bootconfig for kernel parameters

In reply to Masami Hiramatsu

Add a section to describe how to use the bootconfig for specifying kernel and init parameters. This is an important section because it is the reason why this document is under the admin-guide.

---
 Documentation/admin-guide/bootconfig.rst |   39 +++++++++++++++++++++++++++++-
 1 file changed, 38 insertions(+), 1 deletion(-)
Documentation/admin-guide/bootconfig.rst +38 -1
index 6a79f2e59396..a1860fc0ca88 100644
@@ -178,7 +178,7 @@ update the boot loader and the kernel image itself as long as the boot
 loader passes the correct initrd file size. If by any chance, the boot
 loader passes a longer size, the kernel fails to find the bootconfig data.
 
-To do this operation, Linux kernel provides "bootconfig" command under
+To do this operation, Linux kernel provides ``bootconfig`` command under
 tools/bootconfig, which allows admin to apply or delete the config file
 to/from initrd image. You can build it by the following command::
 
@@ -196,6 +196,43 @@ To remove the config from the image, you can use -d option as below::
 Then add "bootconfig" on the normal kernel command line to tell the
 kernel to look for the bootconfig at the end of the initrd file.
 
+
+Kernel parameters via Boot Config
+=================================
+
+In addition to the kernel command line, the boot config can be used for
+passing the kernel parameters. All the key-value pairs under ``kernel``
+key will be passed to kernel cmdline directly. Moreover, the key-value
+pairs under ``init`` will be passed to init process via the cmdline.
+The parameters are concatinated with user-given kernel cmdline string
+as the following order, so that the command line parameter can override
+bootconfig parameters (this depends on how the subsystem handles parameters
+but in general, earlier parameter will be overwritten by later one.)::
+
+ [bootconfig params][cmdline params] -- [bootconfig init params][cmdline init params]
+
+Here is an example of the bootconfig file for kernel/init parameters.::
+
+ kernel {
+   root = 01234567-89ab-cdef-0123-456789abcd
+ }
+ init {
+  splash
+ }
+
+This will be copied into the kernel cmdline string as the following::
+
+ root="01234567-89ab-cdef-0123-456789abcd" -- splash
+
+If user gives some other command line like,::
+
+ ro bootconfig -- quiet
+
+The final kernel cmdline will be the following::
+
+ root="01234567-89ab-cdef-0123-456789abcd" ro bootconfig -- splash quiet
+
+
 Config File Limitation
 ======================
 
#2 lore raw

Re: [PATCH 1/3] init: bootconfig: Remove all bootconfig data when the init memory is removed

In reply to Masami Hiramatsu
I love your patch! Yet something to improve:

Hi Masami,

I love your patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v5.14-rc7 next-20210826]
[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/Masami-Hiramatsu/bootconfig-Cleanup-and-reorder-the-init-parameter-from-bootconfig/20210826-171355
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 73f3af7b4611d77bdaea303fb639333eb28e37d7
config: arc-randconfig-r043-20210826 (attached as .config)
compiler: arc-elf-gcc (GCC) 11.2.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/61f0020919a35211a559e16843b94f5429b1aba3
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Masami-Hiramatsu/bootconfig-Cleanup-and-reorder-the-init-parameter-from-bootconfig/20210826-171355 git checkout 61f0020919a35211a559e16843b94f5429b1aba3
# save the attached .config to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=arc SHELL=/bin/bash

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

All errors (new ones prefixed by >>):

arc-elf-ld: init/main.o: in function `kernel_init':

>> main.c:(.ref.text+0x1fc): undefined reference to `xbc_destroy_all'
>> arc-elf-ld: main.c:(.ref.text+0x1fc): undefined reference to `xbc_destroy_all'

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#3 lore raw

Re: [PATCH 1/3] init: bootconfig: Remove all bootconfig data when the init memory is removed

In reply to Masami Hiramatsu
I love your patch! Yet something to improve:

Hi Masami,

I love your patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v5.14-rc7 next-20210826]
[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/Masami-Hiramatsu/bootconfig-Cleanup-and-reorder-the-init-parameter-from-bootconfig/20210826-171355
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 73f3af7b4611d77bdaea303fb639333eb28e37d7
config: arc-axs101_defconfig (attached as .config)
compiler: arc-elf-gcc (GCC) 11.2.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/61f0020919a35211a559e16843b94f5429b1aba3
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Masami-Hiramatsu/bootconfig-Cleanup-and-reorder-the-init-parameter-from-bootconfig/20210826-171355 git checkout 61f0020919a35211a559e16843b94f5429b1aba3
# save the attached .config to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=arc SHELL=/bin/bash

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

All errors (new ones prefixed by >>):

arc-elf-ld: init/main.o: in function `kernel_init':
main.c:(.ref.text+0xba): undefined reference to `xbc_destroy_all'

>> arc-elf-ld: main.c:(.ref.text+0xba): undefined reference to `xbc_destroy_all'

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

author maintainer
#4 lore raw

Re: [PATCH 1/3] init: bootconfig: Remove all bootconfig data when the init memory is removed

In reply to Masami Hiramatsu
Quoted 14 lines · On Thu, 26 Aug 2021 18:12:07 +0900 Masami Hiramatsu <[email protected]> wrote:

Since the bootconfig is used only in the init functions, it doesn't need to keep the data after boot. Free it when the init memory is removed.

---
 init/main.c |    1 +
 1 file changed, 1 insertion(+)
init/main.c +0 -0
index 8d97aba78c3a..d9b0a99bb2dd 100644

init/main.c static int __ref kernel_init(void *unused) · line 1496

Quoted 4 lines
init/main.c +1 -0
@@ -1493,6 +1493,7 @@ static int __ref kernel_init(void *unused)
 	kprobe_free_init_mem();
 	ftrace_free_init_mem();
 	kgdb_free_init_mem();
+	xbc_destroy_all();

Oops, xbc_destroy_all() is not defined if CONFIG_BOOT_CONFIG=n. Let me fix that.

Thanks,

Quoted 4 lines
init/main.c +0 -0
 	free_initmem();
 	mark_readonly();
 
Signature · 1 line
Masami Hiramatsu <[email protected]>