* [PATCH v2 1/3] init: bootconfig: Remove all bootconfig data when the init memory is removed
2021-08-27 2:16 [PATCH v2 0/3] bootconfig: Cleanup and reorder the init parameter from bootconfig Masami Hiramatsu
@ 2021-08-27 2:16 ` Masami Hiramatsu
2021-08-27 2:16 ` [PATCH v2 2/3] init/bootconfig: Reorder init parameter from bootconfig and cmdline Masami Hiramatsu
2021-08-27 2:16 ` [PATCH v2 3/3] docs: bootconfig: Add how to use bootconfig for kernel parameters Masami Hiramatsu
2 siblings, 0 replies; 4+ messages in thread
From: Masami Hiramatsu @ 2021-08-27 2:16 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>
---
Changes in v2:
- introduce exit_boot_config() wrapper for !CONFIG_BOOT_CONFIG
---
init/main.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/init/main.c b/init/main.c
index 8d97aba78c3a..d35c4a865adb 100644
--- a/init/main.c
+++ b/init/main.c
@@ -468,7 +468,12 @@ static void __init setup_boot_config(void)
return;
}
-#else
+static void __init exit_boot_config(void)
+{
+ xbc_destroy_all();
+}
+
+#else /* !CONFIG_BOOT_CONFIG */
static void __init setup_boot_config(void)
{
@@ -481,7 +486,11 @@ static int __init warn_bootconfig(char *str)
pr_warn("WARNING: 'bootconfig' found on the kernel command line but CONFIG_BOOT_CONFIG is not set.\n");
return 0;
}
-#endif
+
+#define exit_boot_config() do {} while (0)
+
+#endif /* CONFIG_BOOT_CONFIG */
+
early_param("bootconfig", warn_bootconfig);
/* Change NUL term back to "=", to make "param" the whole string. */
@@ -1493,6 +1502,7 @@ static int __ref kernel_init(void *unused)
kprobe_free_init_mem();
ftrace_free_init_mem();
kgdb_free_init_mem();
+ exit_boot_config();
free_initmem();
mark_readonly();
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH v2 2/3] init/bootconfig: Reorder init parameter from bootconfig and cmdline
2021-08-27 2:16 [PATCH v2 0/3] bootconfig: Cleanup and reorder the init parameter from bootconfig Masami Hiramatsu
2021-08-27 2:16 ` [PATCH v2 1/3] init: bootconfig: Remove all bootconfig data when the init memory is removed Masami Hiramatsu
@ 2021-08-27 2:16 ` Masami Hiramatsu
2021-08-27 2:16 ` [PATCH v2 3/3] docs: bootconfig: Add how to use bootconfig for kernel parameters Masami Hiramatsu
2 siblings, 0 replies; 4+ messages in thread
From: Masami Hiramatsu @ 2021-08-27 2:16 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 d35c4a865adb..d08caed17c7f 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");
@@ -655,16 +655,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] 4+ messages in thread* [PATCH v2 3/3] docs: bootconfig: Add how to use bootconfig for kernel parameters
2021-08-27 2:16 [PATCH v2 0/3] bootconfig: Cleanup and reorder the init parameter from bootconfig Masami Hiramatsu
2021-08-27 2:16 ` [PATCH v2 1/3] init: bootconfig: Remove all bootconfig data when the init memory is removed Masami Hiramatsu
2021-08-27 2:16 ` [PATCH v2 2/3] init/bootconfig: Reorder init parameter from bootconfig and cmdline Masami Hiramatsu
@ 2021-08-27 2:16 ` Masami Hiramatsu
2 siblings, 0 replies; 4+ messages in thread
From: Masami Hiramatsu @ 2021-08-27 2:16 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] 4+ messages in thread