linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] bootconfig: Cleanup and reorder the init parameter from bootconfig
@ 2021-08-26  9:11 Masami Hiramatsu
  2021-08-26  9:12 ` [PATCH 1/3] init: bootconfig: Remove all bootconfig data when the init memory is removed Masami Hiramatsu
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Masami Hiramatsu @ 2021-08-26  9:11 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: Masami Hiramatsu, LKML

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) <mhiramat@kernel.org>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/3] init: bootconfig: Remove all bootconfig data when the init memory is removed
  2021-08-26  9:11 [PATCH 0/3] bootconfig: Cleanup and reorder the init parameter from bootconfig Masami Hiramatsu
@ 2021-08-26  9:12 ` Masami Hiramatsu
  2021-08-26 14:04   ` kernel test robot
                     ` (2 more replies)
  2021-08-26  9:12 ` [PATCH 2/3] init/bootconfig: Reorder init parameter from bootconfig and cmdline Masami Hiramatsu
  2021-08-26  9:12 ` [PATCH 3/3] docs: bootconfig: Add how to use bootconfig for kernel parameters Masami Hiramatsu
  2 siblings, 3 replies; 7+ messages in thread
From: Masami Hiramatsu @ 2021-08-26  9:12 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: Masami Hiramatsu, LKML

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.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 init/main.c |    1 +
 1 file changed, 1 insertion(+)

diff --git a/init/main.c b/init/main.c
index 8d97aba78c3a..d9b0a99bb2dd 100644
--- a/init/main.c
+++ b/init/main.c
@@ -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();
 


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/3] init/bootconfig: Reorder init parameter from bootconfig and cmdline
  2021-08-26  9:11 [PATCH 0/3] bootconfig: Cleanup and reorder the init parameter from bootconfig Masami Hiramatsu
  2021-08-26  9:12 ` [PATCH 1/3] init: bootconfig: Remove all bootconfig data when the init memory is removed Masami Hiramatsu
@ 2021-08-26  9:12 ` Masami Hiramatsu
  2021-08-26  9:12 ` [PATCH 3/3] docs: bootconfig: Add how to use bootconfig for kernel parameters Masami Hiramatsu
  2 siblings, 0 replies; 7+ messages in thread
From: Masami Hiramatsu @ 2021-08-26  9:12 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: Masami Hiramatsu, LKML

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.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 init/main.c |   23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/init/main.c b/init/main.c
index d9b0a99bb2dd..b24a18aebed7 100644
--- a/init/main.c
+++ b/init/main.c
@@ -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);
 	}
 }
 


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/3] docs: bootconfig: Add how to use bootconfig for kernel parameters
  2021-08-26  9:11 [PATCH 0/3] bootconfig: Cleanup and reorder the init parameter from bootconfig Masami Hiramatsu
  2021-08-26  9:12 ` [PATCH 1/3] init: bootconfig: Remove all bootconfig data when the init memory is removed Masami Hiramatsu
  2021-08-26  9:12 ` [PATCH 2/3] init/bootconfig: Reorder init parameter from bootconfig and cmdline Masami Hiramatsu
@ 2021-08-26  9:12 ` Masami Hiramatsu
  2 siblings, 0 replies; 7+ messages in thread
From: Masami Hiramatsu @ 2021-08-26  9:12 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: Masami Hiramatsu, LKML, Jonathan Corbet, linux-doc

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.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: linux-doc@vger.kernel.org
---
 Documentation/admin-guide/bootconfig.rst |   39 +++++++++++++++++++++++++++++-
 1 file changed, 38 insertions(+), 1 deletion(-)

diff --git a/Documentation/admin-guide/bootconfig.rst b/Documentation/admin-guide/bootconfig.rst
index 6a79f2e59396..a1860fc0ca88 100644
--- a/Documentation/admin-guide/bootconfig.rst
+++ b/Documentation/admin-guide/bootconfig.rst
@@ -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
 ======================
 


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/3] init: bootconfig: Remove all bootconfig data when the init memory is removed
  2021-08-26  9:12 ` [PATCH 1/3] init: bootconfig: Remove all bootconfig data when the init memory is removed Masami Hiramatsu
@ 2021-08-26 14:04   ` kernel test robot
  2021-08-26 14:04   ` kernel test robot
  2021-08-26 14:27   ` Masami Hiramatsu
  2 siblings, 0 replies; 7+ messages in thread
From: kernel test robot @ 2021-08-26 14:04 UTC (permalink / raw)
  To: Masami Hiramatsu, Steven Rostedt; +Cc: kbuild-all, Masami Hiramatsu, LKML

[-- Attachment #1: Type: text/plain, Size: 1889 bytes --]

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
Reported-by: kernel test robot <lkp@intel.com>

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@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 19785 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/3] init: bootconfig: Remove all bootconfig data when the init memory is removed
  2021-08-26  9:12 ` [PATCH 1/3] init: bootconfig: Remove all bootconfig data when the init memory is removed Masami Hiramatsu
  2021-08-26 14:04   ` kernel test robot
@ 2021-08-26 14:04   ` kernel test robot
  2021-08-26 14:27   ` Masami Hiramatsu
  2 siblings, 0 replies; 7+ messages in thread
From: kernel test robot @ 2021-08-26 14:04 UTC (permalink / raw)
  To: Masami Hiramatsu, Steven Rostedt; +Cc: kbuild-all, Masami Hiramatsu, LKML

[-- Attachment #1: Type: text/plain, Size: 1879 bytes --]

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
Reported-by: kernel test robot <lkp@intel.com>

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@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 15647 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/3] init: bootconfig: Remove all bootconfig data when the init memory is removed
  2021-08-26  9:12 ` [PATCH 1/3] init: bootconfig: Remove all bootconfig data when the init memory is removed Masami Hiramatsu
  2021-08-26 14:04   ` kernel test robot
  2021-08-26 14:04   ` kernel test robot
@ 2021-08-26 14:27   ` Masami Hiramatsu
  2 siblings, 0 replies; 7+ messages in thread
From: Masami Hiramatsu @ 2021-08-26 14:27 UTC (permalink / raw)
  To: Masami Hiramatsu; +Cc: Steven Rostedt, LKML

On Thu, 26 Aug 2021 18:12:07 +0900
Masami Hiramatsu <mhiramat@kernel.org> 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.
> 
> Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
> ---
>  init/main.c |    1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/init/main.c b/init/main.c
> index 8d97aba78c3a..d9b0a99bb2dd 100644
> --- a/init/main.c
> +++ b/init/main.c
> @@ -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,

>  	free_initmem();
>  	mark_readonly();
>  
> 


-- 
Masami Hiramatsu <mhiramat@kernel.org>

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-08-26 14:27 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-26  9:11 [PATCH 0/3] bootconfig: Cleanup and reorder the init parameter from bootconfig Masami Hiramatsu
2021-08-26  9:12 ` [PATCH 1/3] init: bootconfig: Remove all bootconfig data when the init memory is removed Masami Hiramatsu
2021-08-26 14:04   ` kernel test robot
2021-08-26 14:04   ` kernel test robot
2021-08-26 14:27   ` Masami Hiramatsu
2021-08-26  9:12 ` [PATCH 2/3] init/bootconfig: Reorder init parameter from bootconfig and cmdline Masami Hiramatsu
2021-08-26  9:12 ` [PATCH 3/3] docs: bootconfig: Add how to use bootconfig for kernel parameters Masami Hiramatsu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).