bootconfig: skip runtime kernel.* render once prepended early

setup_boot_config() folds the embedded bootconfig "kernel" subtree into
the command line via xbc_make_cmdline("kernel"). A subsequent patch lets
an architecture prepend the build-time-rendered embedded "kernel" keys
to boot_command_line early in setup_arch(); rendering them again here
would then duplicate every key in saved_command_line and make
accumulating handlers (console=, earlycon=, ...) re-register the same
value.

Track whether the bootconfig data came from the embedded source
(from_embedded) and skip the runtime render only when the early prepend
actually happened, as reported by xbc_embedded_cmdline_applied(). On
architectures that do not select ARCH_SUPPORTS_CMDLINE_FROM_BOOTCONFIG
that helper is a stub returning false, so this path is unchanged and the
embedded "kernel" keys still reach the cmdline via the runtime parser
exactly as before.

Link: https://lore.kernel.org/all/20260626-bootconfig_using_tools-v7-8-24ab72139c29@debian.org/

Signed-off-by: Breno Leitao <leitao@debian.org>
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
This commit is contained in:
Breno Leitao 2026-07-02 21:15:46 +09:00 committed by Masami Hiramatsu (Google)
parent bfdf7ec54f
commit 378517ca3b

View File

@ -378,12 +378,15 @@ static void __init setup_boot_config(void)
int pos, ret;
size_t size;
char *err;
bool from_embedded = false;
/* Cut out the bootconfig data even if we have no bootconfig option */
data = get_boot_config_from_initrd(&size);
/* If there is no bootconfig in initrd, try embedded one. */
if (!data)
if (!data) {
data = xbc_get_embedded_bootconfig(&size);
from_embedded = true;
}
strscpy(tmp_cmdline, boot_command_line, COMMAND_LINE_SIZE);
err = parse_args("bootconfig", tmp_cmdline, NULL, 0, 0, 0, NULL,
@ -421,8 +424,24 @@ static void __init setup_boot_config(void)
} else {
xbc_get_info(&ret, NULL);
pr_info("Load bootconfig: %ld bytes %d nodes\n", (long)size, ret);
/* keys starting with "kernel." are passed via cmdline */
extra_command_line = xbc_make_cmdline("kernel");
/*
* keys starting with "kernel." are passed via cmdline. When
* this bootconfig came from the embedded source and
* setup_arch() already prepended the rendered "kernel" subtree
* to boot_command_line, rendering again here would duplicate
* the keys in saved_command_line and make accumulating handlers
* (console=, earlycon=, ...) re-register the same value. Skip
* only when the prepend really happened.
*
* On arches that do not select ARCH_SUPPORTS_CMDLINE_FROM_BOOTCONFIG,
* CONFIG_CMDLINE_FROM_BOOTCONFIG is unselectable and
* xbc_embedded_cmdline_applied() collapses to a stub returning
* false, so this path still runs and the embedded "kernel"
* keys reach the cmdline via the runtime parser exactly as
* before this series.
*/
if (!from_embedded || !xbc_embedded_cmdline_applied())
extra_command_line = xbc_make_cmdline("kernel");
/* Also, "init." keys are init arguments */
extra_init_args = xbc_make_cmdline("init");
}