Skip to contentSkip to conversation

bootconfig: embed kernel.* cmdline at build time

PATCH Superseded Breno Leitao 4 participants 17 messages Jun 9 – Jun 23

Subsystems (7)

v4 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v4 cover bootconfig: embed kernel.* cmdline at build time

The userspace pieces (xbc_snprint_cmdline() in lib/, tools/bootconfig -C) already landed; this series wires the rendered cmdline into the kernel.

Motivation: today the embedded bootconfig is parsed at runtime, after parse_early_param() has already run, so early_param() handlers can't see embedded values. Folding the kernel.* subtree into the cmdline at build time gives a CONFIG_CMDLINE-equivalent for embedded-bootconfig users without forcing them to maintain two cmdline sources.

Behaviorally, the "kernel" subtree is rendered to a flat string at build time and stashed in .init.rodata. setup_arch() prepends it to boot_command_line before parse_early_param() runs. Overflow is a soft
error: the helper logs and leaves boot_command_line untouched rather than panicking, so an oversized embedded bconf cannot brick a boot.

---
Changes in v4:
- Patch 3 (build pipeline): clear CROSS_COMPILE= in the kernel-side
tools/bootconfig sub-make. Without it, an LLVM=1 cross build
inherits CROSS_COMPILE and tools/scripts/Makefile.include injects --target=/--sysroot= into the host clang, producing a target
binary that fails to exec.
- Patch 3 (build pipeline): place embedded-cmdline.S in its own .init.rodata.embed_cmdline subsection ("a") so ld.lld does not
see a section-type mismatch against lib/bootconfig-data.S's
writable .init.rodata ("aw"). The linker's *(.init.rodata
.init.rodata.*) glob still folds it into the init image.
- Patch 6 (x86/setup): also accept the bootconfig=<anything> form
via cmdline_find_option(), matching the runtime parse_args() loop.
Without it, bootconfig=0/=off would skip the early prepend but
still trigger the late runtime apply -- a split-brain state.
- New patch 7: document CONFIG_BOOT_CONFIG_EMBED_CMDLINE in Documentation/admin-guide/bootconfig.rst (semantics, opt-in,
precedence, overflow behavior, example).
- Link to v3: https://lore.kernel.org/r/[email protected]

Changes in v3:
- Patch 3: Move HOSTCC override to the kernel-side rule; tool keeps $(CC) for standalone/cross builds.
- Patch 6: Drop the false fail-safe wording; document the BOOT_CONFIG_FORCE=y default interaction.
- Link to v2:
https://lore.kernel.org/r/[email protected]

Changes in v2 (addressing review of v1):
- Split out a standalone fix for the NULL-pointer arithmetic in xbc_snprint_cmdline() so the build-time render cannot trip host UBSan/FORTIFY_SOURCE.
- Rework the leaf-root handling: instead of returning early, skip @root
inside the loop so a root carrying both a value and subkeys
(kernel = x together with kernel.foo = bar) still renders its
descendant keys.
- Build tools/bootconfig with $(HOSTCC) so cross-compiled (ARCH=...)
builds render the cmdline on the build host instead of failing with
"Exec format error".
- Mark the embedded cmdline section read-only (drop the "w" flag from .init.rodata).
- Add a make-clean hook so tools/bootconfig artifacts are removed by
make clean.
- Gate the x86 prepend on "bootconfig" being present on the command
line (or CONFIG_BOOT_CONFIG_FORCE), matching the init.* opt-in
semantics documented in bootconfig.rst and preserving fail-safe
recovery: dropping "bootconfig" from the bootloader cmdline now also
disables the embedded kernel.* keys.
- Link to v1: https://patch.msgid.link/[email protected]

---
Breno Leitao (7):
bootconfig: fix NULL-pointer arithmetic in xbc_snprint_cmdline()
bootconfig: render descendant keys when xbc_snprint_cmdline() root has a value
bootconfig: render embedded bootconfig as a kernel cmdline at build time
bootconfig: clean build-time tools/bootconfig from make clean
bootconfig: add xbc_prepend_embedded_cmdline() helper
Documentation: bootconfig: document build-time cmdline rendering x86/setup: prepend embedded bootconfig cmdline before parse_early_param

 Documentation/admin-guide/bootconfig.rst |  46 +++++++++++++
 MAINTAINERS                              |   1 +
 Makefile                                 |  28 +++++++-
 arch/x86/Kconfig                         |   1 +
 arch/x86/kernel/setup.c                  |  27 ++++++++
 include/linux/bootconfig.h               |   9 +++
 init/Kconfig                             |  36 ++++++++++
 init/main.c                              |  25 ++++++-
 lib/Makefile                             |  16 +++++
 lib/bootconfig.c                         | 112 +++++++++++++++++++++++++++++--
 lib/embedded-cmdline.S                   |  16 +++++
 tools/bootconfig/Makefile                |   4 +-
 12 files changed, 308 insertions(+), 13 deletions(-)

---
base-commit: a87737435cfa134f9cdcc696ba3080759d04cf72
change-id: 20260508-bootconfig_using_tools-cfa7aa9d6a5a

Best regards,

Signature · 1 line
Breno Leitao <[email protected]>
#1 lore raw

PATCH v4 1/7 bootconfig: fix NULL-pointer arithmetic in xbc_snprint_cmdline()

xbc_snprint_cmdline() is meant to be called twice: first with buf=NULL, size=0 to probe the rendered length, then with a real buffer to fill it (the standard snprintf() two-pass pattern). The probe call makes the function compute "buf + size" (NULL + 0) and, on every iteration, advance "buf += ret" from that NULL base and pass the result back into snprintf().

Pointer arithmetic on a NULL pointer is undefined behavior. It is harmless in the in-kernel callers today, but the follow-up patches run this same code in the userspace tools/bootconfig parser at kernel build time, where host UBSan / FORTIFY_SOURCE abort the build.

Track a running written length (size_t) instead of mutating @buf, and only form "buf + len" when @buf is non-NULL. snprintf(NULL, 0, ...) is itself well defined and returns the would-be length, so the two-pass "probe then fill" usage returns identical byte counts.

---
 lib/bootconfig.c | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)
lib/bootconfig.c +16 -7
index f445b7703fdd..2ed9ee3dc81c 100644
@@ -427,10 +427,18 @@ static char xbc_namebuf[XBC_KEYLEN_MAX] __initdata;
 int __init xbc_snprint_cmdline(char *buf, size_t size, struct xbc_node *root)
 {
 	struct xbc_node *knode, *vnode;
-	char *end = buf + size;
 	const char *val, *q;
+	size_t len = 0;
 	int ret;
 
+	/*
+	 * Track the running written length rather than advancing @buf, so we
+	 * never form "buf + size" or "buf += ret" while @buf is NULL (the
+	 * size-probe call passes buf=NULL, size=0). NULL pointer arithmetic
+	 * is undefined behavior and trips host UBSan / FORTIFY_SOURCE when
+	 * this renderer runs at kernel build time. snprintf(NULL, 0, ...)
+	 * itself is well defined and returns the would-be length.
+	 */
 	xbc_node_for_each_key_value(root, knode, val) {
 		ret = xbc_node_compose_key_after(root, knode,
 					xbc_namebuf, XBC_KEYLEN_MAX);
@@ -439,10 +447,11 @@ int __init xbc_snprint_cmdline(char *buf, size_t size, struct xbc_node *root)
 
 		vnode = xbc_node_get_child(knode);
 		if (!vnode) {
-			ret = snprintf(buf, rest(buf, end), "%s ", xbc_namebuf);
+			ret = snprintf(buf ? buf + len : NULL, rest(len, size),
+				       "%s ", xbc_namebuf);
 			if (ret < 0)
 				return ret;
-			buf += ret;
+			len += ret;
 			continue;
 		}
 		xbc_array_for_each_value(vnode, val) {
@@ -452,15 +461,15 @@ int __init xbc_snprint_cmdline(char *buf, size_t size, struct xbc_node *root)
 			 * whitespace.
 			 */
 			q = strpbrk(val, " \t\r\n") ? "\"" : "";
-			ret = snprintf(buf, rest(buf, end), "%s=%s%s%s ",
-				       xbc_namebuf, q, val, q);
+			ret = snprintf(buf ? buf + len : NULL, rest(len, size),
+				       "%s=%s%s%s ", xbc_namebuf, q, val, q);
 			if (ret < 0)
 				return ret;
-			buf += ret;
+			len += ret;
 		}
 	}
 
-	return buf - (end - size);
+	return len;
 }
 #undef rest
 
Signature · 1 line
2.53.0-Meta
#2 lore raw

PATCH v4 2/7 bootconfig: render descendant keys when xbc_snprint_cmdline() root has a value

In reply to Breno Leitao

xbc_node_for_each_key_value() walks to the first leaf under @root, and when @root is itself a leaf it yields @root. That happens not only for an empty "kernel {}" subtree, but also when @root carries both a value and subkeys, e.g.

kernel = x
kernel.foo = bar

Here @root ("kernel") is a leaf because its first child is the value node "x", so the iterator returns @root first. Feeding @root back into xbc_node_compose_key_after(root, root) returns -EINVAL, which the only in-kernel caller papers over with a "len <= 0" check -- but the follow-up tools/bootconfig -C user propagates the error and turns such a bootconfig into a build failure. Worse, short-circuiting the whole call on a leaf @root would silently drop the valid "kernel.foo = bar" descendant that this patch should render.

Skip @root inside the loop instead of bailing out: the value-only entry is dropped (it is rendered through the "kernel" cmdline path, not here), while real descendant keys are still emitted. An entirely empty subtree now renders nothing and returns 0 rather than -EINVAL, matching the "nothing to render is not an error" semantics expected by the new build-time caller.

---
 lib/bootconfig.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
lib/bootconfig.c +11 -0
index 2ed9ee3dc81c..926094d97397 100644
@@ -440,6 +440,17 @@ int __init xbc_snprint_cmdline(char *buf, size_t size, struct xbc_node *root)
 	 * itself is well defined and returns the would-be length.
 	 */
 	xbc_node_for_each_key_value(root, knode, val) {
+		/*
+		 * An empty or value-only @root (e.g. "kernel {}" or
+		 * "kernel = x", possibly alongside "kernel.foo = bar")
+		 * yields @root itself here. Skip it: composing a key for it
+		 * would fail with -EINVAL, yet any real descendant keys must
+		 * still be rendered. An entirely empty subtree then renders
+		 * nothing and returns 0 rather than an error.
+		 */
+		if (knode == root)
+			continue;
+
 		ret = xbc_node_compose_key_after(root, knode,
 					xbc_namebuf, XBC_KEYLEN_MAX);
 		if (ret < 0)
Signature · 1 line
2.53.0-Meta
#3 lore raw

PATCH v4 3/7 bootconfig: render embedded bootconfig as a kernel cmdline at build time

In reply to Breno Leitao

Add the build-time pipeline that renders the "kernel" subtree of CONFIG_BOOT_CONFIG_EMBED_FILE into a flat cmdline string and stashes it in .init.rodata as embedded_kernel_cmdline[]. A follow-up patch adds the runtime helper that prepends this string to boot_command_line during early architecture setup so parse_early_param() sees the values.

The build wires up:
tools/bootconfig -C kernel - userspace tool already shared with
lib/bootconfig.c, used here in -C mode to render a bootconfig file to a cmdline
lib/embedded-cmdline.S - .incbin's the rendered text plus a NUL
(listed under the EXTRA BOOT CONFIG MAINTAINERS entry)
lib/Makefile rule - runs tools/bootconfig at build time
Makefile prepare dep - ensures tools/bootconfig is built first,
same pattern as tools/objtool and tools/bpf/resolve_btfids

Drop the test target from tools/bootconfig/Makefile's default 'all' recipe so that hooking the binary into the kernel build does not run test-bootconfig.sh on every prepare. The tests stay available as 'make -C tools/bootconfig test', matching the convention of tools/objtool and tools/bpf/resolve_btfids whose 'all' targets only build the binary.

Require BOOT_CONFIG_EMBED_FILE to be non-empty before the new option can be enabled, otherwise tools/bootconfig -C runs against an empty file and prints a parse error on every kernel build.

The feature gates on CONFIG_ARCH_SUPPORTS_CMDLINE_FROM_BOOTCONFIG, a silent symbol arches select once they've wired the prepend call into setup_arch(). No arch selects it in this patch, so the user-visible CONFIG_BOOT_CONFIG_EMBED_CMDLINE is not yet enableable; when an arch later opts in, the runtime behavior is added by the follow-up patches.

tools/bootconfig also installs on target systems, so its own Makefile keeps $(CC) and stays cross-buildable as a standalone tool. The kernel build, which runs the tool on the build host during prepare, instead forces CC=$(HOSTCC) from a dedicated tools/bootconfig rule and clears CROSS_COMPILE= in the sub-make. Without that clear, an LLVM=1 cross build would inherit CROSS_COMPILE and tools/scripts/Makefile.include would inject --target=/--sysroot= flags into the host clang invocation, producing a target binary that fails to exec ("Exec format error").

embedded-cmdline.S places the rendered string in its own .init.rodata subsection (.init.rodata.embed_cmdline) with the "a" (allocatable, read-only) flag and %progbits. lib/bootconfig-data.S already places the embedded bootconfig blob in .init.rodata with the "aw" flag (xbc_init() rewrites separators in place, so that data must be writable). Using a distinct subsection name avoids the ld.lld section- type mismatch that would otherwise arise from mixing "a" and "aw" under the same name; the linker's "*(.init.rodata .init.rodata.*)" glob still folds both into the init image and frees them after boot.

A follow-up patch wires the build-time tools/bootconfig into the top-level clean target.

---
 MAINTAINERS               |  1 +
 Makefile                  | 15 +++++++++++++++
 init/Kconfig              | 36 ++++++++++++++++++++++++++++++++++++
 lib/Makefile              | 16 ++++++++++++++++
 lib/embedded-cmdline.S    | 16 ++++++++++++++++
 tools/bootconfig/Makefile |  2 +-
 6 files changed, 85 insertions(+), 1 deletion(-)
MAINTAINERS +1 -0
index 57656ec0e9d5..953231df1911 100644
@@ -9844,6 +9844,7 @@ F:	fs/proc/bootconfig.c
 F:	include/linux/bootconfig.h
 F:	lib/bootconfig-data.S
 F:	lib/bootconfig.c
+F:	lib/embedded-cmdline.S
 F:	tools/bootconfig/*
 F:	tools/bootconfig/scripts/*
 
Makefile +15 -0
index bf196c6df5b9..a7abb3f9a626 100644
@@ -1545,6 +1545,21 @@ prepare: tools/bpf/resolve_btfids
 endif
 endif
 
+# tools/bootconfig renders the embedded bootconfig into a cmdline at build time.
+ifdef CONFIG_BOOT_CONFIG_EMBED_CMDLINE
+prepare: tools/bootconfig
+endif
+
+# tools/bootconfig is run on the build host during prepare, so force a host
+# binary here; its own Makefile keeps $(CC) for standalone and cross builds.
+# CROSS_COMPILE= is cleared so tools/scripts/Makefile.include does not inject
+# the target's --target=/--sysroot= flags into the host clang invocation under
+# LLVM=1 cross builds (which would produce a target binary that fails to exec).
+tools/bootconfig: FORCE
+	$(Q)mkdir -p $(objtree)/tools
+	$(Q)$(MAKE) O=$(abspath $(objtree)) subdir=tools -C $(srctree)/tools/ \
+		bootconfig CC=$(HOSTCC) CROSS_COMPILE=
+
 # The tools build system is not a part of Kbuild and tends to introduce
 # its own unique issues. If you need to integrate a new tool into Kbuild,
 # please consider locating that tool outside the tools/ tree and using the
init/Kconfig +36 -0
index 5230d4879b1c..743f54397190 100644
@@ -1566,6 +1566,42 @@ config BOOT_CONFIG_EMBED_FILE
 	  This bootconfig will be used if there is no initrd or no other
 	  bootconfig in the initrd.
 
+config ARCH_SUPPORTS_CMDLINE_FROM_BOOTCONFIG
+	bool
+	help
+	  Silent symbol; no C code reads it directly. Architectures
+	  select it once their setup_arch() calls
+	  xbc_prepend_embedded_cmdline() before parse_early_param().
+	  Its only role is to gate the user-visible
+	  BOOT_CONFIG_EMBED_CMDLINE option per-arch, the same
+	  ARCH_SUPPORTS_* idiom used by ARCH_SUPPORTS_CFI, etc.
+
+config BOOT_CONFIG_EMBED_CMDLINE
+	bool "Render embedded bootconfig as kernel cmdline at build time"
+	depends on BOOT_CONFIG_EMBED
+	depends on BOOT_CONFIG_EMBED_FILE != ""
+	depends on ARCH_SUPPORTS_CMDLINE_FROM_BOOTCONFIG
+	default n
+	help
+	  Render the "kernel" subtree of the embedded bootconfig file into a
+	  flat cmdline string at kernel build time and prepend it to
+	  boot_command_line during early architecture setup. This makes
+	  early_param() handlers (e.g. mem=, earlycon=, loglevel=) see the
+	  values supplied via the embedded bootconfig.
+
+	  The runtime bootconfig parser is unaffected, so tree-structured
+	  consumers such as ftrace boot-time tracing keep working.
+
+	  Note: when an initrd also carries a bootconfig, its "kernel"
+	  subtree is still parsed at runtime, but the embedded "kernel"
+	  keys remain in boot_command_line for parse_early_param() and
+	  end up later than the initrd keys in saved_command_line, so
+	  parse_args() last-wins favors the embedded values. If you need
+	  initrd to override embedded kernel.* keys, leave this option
+	  off.
+
+	  If unsure, say N.
+
 config CMDLINE_LOG_WRAP_IDEAL_LEN
 	int "Length to try to wrap the cmdline when logged at boot"
 	default 1021
lib/Makefile +16 -0
index 7f75cc6edf94..4ace86a5cb6d 100644
@@ -273,6 +273,22 @@ filechk_defbconf = cat $(or $(real-prereqs), /dev/null)
 $(obj)/default.bconf: $(CONFIG_BOOT_CONFIG_EMBED_FILE) FORCE
 	$(call filechk,defbconf)
 
+obj-$(CONFIG_BOOT_CONFIG_EMBED_CMDLINE) += embedded-cmdline.o
+$(obj)/embedded-cmdline.o: $(obj)/embedded_cmdline.bin
+
+# Render the bootconfig "kernel" subtree to a flat cmdline string using
+# the userspace tools/bootconfig parser (-C mode). The runtime prepend
+# helper enforces COMMAND_LINE_SIZE at boot, so no build-time size
+# check is performed here (COMMAND_LINE_SIZE is an arch header
+# constant, not a Kconfig value).
+quiet_cmd_render_cmdline = BCONF2C $@
+      cmd_render_cmdline = \
+	$(objtree)/tools/bootconfig/bootconfig -C $< > $@
+
+targets += embedded_cmdline.bin
+$(obj)/embedded_cmdline.bin: $(obj)/default.bconf $(objtree)/tools/bootconfig/bootconfig FORCE
+	$(call if_changed,render_cmdline)
+
 obj-$(CONFIG_RBTREE_TEST) += rbtree_test.o
 obj-$(CONFIG_INTERVAL_TREE_TEST) += interval_tree_test.o
 
lib/embedded-cmdline.S new file +16 -0
new file mode 100644
index 000000000000..bda81b4a42be
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Embed the build-time-rendered bootconfig "kernel" subtree as a flat
+ * cmdline string. setup_arch() prepends this to boot_command_line on
+ * architectures that select ARCH_SUPPORTS_CMDLINE_FROM_BOOTCONFIG.
+ *
+ * Copyright (c) 2026 Meta Platforms, Inc. and affiliates
+ * Copyright (c) 2026 Breno Leitao <[email protected]>
+ */
+	.section .init.rodata.embed_cmdline, "a", %progbits
+	.global embedded_kernel_cmdline
+embedded_kernel_cmdline:
+	.incbin "lib/embedded_cmdline.bin"
+	.byte 0
+	.global embedded_kernel_cmdline_end
+embedded_kernel_cmdline_end:
tools/bootconfig/Makefile +1 -1
index 90eb47c9d8de..4e82fd9553cd 100644
@@ -15,7 +15,7 @@ override CFLAGS += -Wall -g -I$(CURDIR)/include
 ALL_TARGETS := bootconfig
 ALL_PROGRAMS := $(patsubst %,$(OUTPUT)%,$(ALL_TARGETS))
 
-all: $(ALL_PROGRAMS) test
+all: $(ALL_PROGRAMS)
 
 $(OUTPUT)bootconfig: main.c include/linux/bootconfig.h $(LIBSRC)
 	$(CC) $(filter %.c,$^) $(CFLAGS) $(LDFLAGS) -o $@
Signature · 1 line
2.53.0-Meta
#6 lore raw

PATCH v4 4/7 bootconfig: clean build-time tools/bootconfig from make clean

In reply to Breno Leitao

The previous patch builds tools/bootconfig during 'make prepare' to render the embedded bootconfig cmdline, but nothing removes it on 'make clean', leaving the compiled tool and its objects behind.

Wire a bootconfig_clean hook into the top-level clean target so the compiled tool and its objects are removed by make clean, matching the prepare-wired tools/objtool and tools/bpf/resolve_btfids.

The hook runs tools/bootconfig's Makefile via $(MAKE), which the kernel build invokes with -rR (MAKEFLAGS += -rR). -rR drops the built-in $(RM) variable, so the existing "$(RM) -f ..." clean recipe would expand to a bare "-f ..." and fail. Spell the recipe with a literal "rm -f" so it keeps working both standalone and when invoked from Kbuild.

---
 Makefile                  | 13 ++++++++++++-
 tools/bootconfig/Makefile |  2 +-
 2 files changed, 13 insertions(+), 2 deletions(-)
Makefile +12 -1
index a7abb3f9a626..a6e13fa1c1dc 100644
@@ -1586,6 +1586,17 @@ ifneq ($(wildcard $(objtool_O)),)
 	$(Q)$(MAKE) -sC $(abs_srctree)/tools/objtool O=$(objtool_O) srctree=$(abs_srctree) $(patsubst objtool_%,%,$@)
 endif
 
+PHONY += bootconfig_clean
+
+bootconfig_O = $(abspath $(objtree))/tools/bootconfig
+
+# tools/bootconfig is only built (via the prepare hook above) when
+# CONFIG_BOOT_CONFIG_EMBED_CMDLINE is set; skip its clean otherwise.
+bootconfig_clean:
+ifneq ($(wildcard $(bootconfig_O)),)
+	$(Q)$(MAKE) -sC $(srctree)/tools/bootconfig O=$(bootconfig_O) clean
+endif
+
 tools/: FORCE
 	$(Q)mkdir -p $(objtree)/tools
 	$(Q)$(MAKE) O=$(abspath $(objtree)) subdir=tools -C $(srctree)/tools/
@@ -1756,7 +1767,7 @@ vmlinuxclean:
 	$(Q)$(CONFIG_SHELL) $(srctree)/scripts/link-vmlinux.sh clean
 	$(Q)$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) clean)
 
-clean: archclean vmlinuxclean resolve_btfids_clean objtool_clean
+clean: archclean vmlinuxclean resolve_btfids_clean objtool_clean bootconfig_clean
 
 # mrproper - Delete all generated files, including .config
 #
tools/bootconfig/Makefile +1 -1
index 4e82fd9553cd..3cb8066d5141 100644
@@ -27,4 +27,4 @@ install: $(ALL_PROGRAMS)
 	install $(OUTPUT)bootconfig $(DESTDIR)$(bindir)
 
 clean:
-	$(RM) -f $(OUTPUT)*.o $(ALL_PROGRAMS)
+	rm -f $(OUTPUT)*.o $(ALL_PROGRAMS)
Signature · 1 line
2.53.0-Meta
#7 lore raw

PATCH v4 5/7 bootconfig: add xbc_prepend_embedded_cmdline() helper

In reply to Breno Leitao

Add a helper that prepends the build-time-rendered embedded bootconfig "kernel" subtree (embedded_kernel_cmdline[] from embedded-cmdline.S) to a cmdline buffer with a separating space. Architectures call this from setup_arch() before parse_early_param() so early_param() handlers (mem=, earlycon=, loglevel=, ...) see values supplied via the embedded bootconfig.

The in-place prepend (shift the existing string right, then drop the embedded string in front) is factored into a small str_prepend() helper.

On overflow the helper logs an error and leaves the cmdline untouched rather than panicking. Booting without the embedded values is better than refusing to boot, and the error tells the user why their embedded keys are missing.

The helper records whether it actually prepended, exposed via xbc_embedded_cmdline_applied(). setup_boot_config() uses this to decide whether the runtime "kernel" render would duplicate keys already folded into boot_command_line.

When CONFIG_BOOT_CONFIG_EMBED_CMDLINE=n, the public declaration in <linux/bootconfig.h> resolves to a no-op stub so callers compile unchanged.

---
 include/linux/bootconfig.h |  9 ++++++
 lib/bootconfig.c           | 78 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 87 insertions(+)
include/linux/bootconfig.h +9 -0
index 1c7f3b74ffcf..c186137f87ac 100644
@@ -308,4 +308,13 @@ static inline const char *xbc_get_embedded_bootconfig(size_t *size)
 }
 #endif
 
+/* Build-time-rendered bootconfig cmdline prepended in setup_arch() */
+#ifdef CONFIG_BOOT_CONFIG_EMBED_CMDLINE
+void __init xbc_prepend_embedded_cmdline(char *dst, size_t size);
+bool __init xbc_embedded_cmdline_applied(void);
+#else
+static inline void xbc_prepend_embedded_cmdline(char *dst, size_t size) { }
+static inline bool xbc_embedded_cmdline_applied(void) { return false; }
+#endif
+
 #endif
lib/bootconfig.c +78 -0

90 lines not on this page · raw message

Signature · 1 line
2.53.0-Meta
#8 lore raw

PATCH v4 6/7 Documentation: bootconfig: document build-time cmdline rendering

In reply to Breno Leitao

Add a section describing CONFIG_BOOT_CONFIG_EMBED_CMDLINE: what it does (renders the embedded "kernel" subtree to a flat cmdline at build time so early_param() handlers see the values), what it requires (BOOT_CONFIG_EMBED, a non-empty BOOT_CONFIG_EMBED_FILE, and ARCH_SUPPORTS_CMDLINE_FROM_BOOTCONFIG -- currently x86 only), the bootconfig opt-in semantics, the initrd-vs-embedded precedence, and the soft-error overflow behavior.

---
 Documentation/admin-guide/bootconfig.rst | 46 ++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)
Documentation/admin-guide/bootconfig.rst +46 -0
index f712758472d5..f371e5cdc974 100644
@@ -234,6 +234,52 @@ Kconfig option selected.
 Note that even if you set this option, you can override the embedded
 bootconfig by another bootconfig which attached to the initrd.
 
+Rendering Embedded kernel.* Keys at Build Time
+----------------------------------------------
+
+By default, the embedded bootconfig (``CONFIG_BOOT_CONFIG_EMBED=y``) is
+parsed at runtime, after ``parse_early_param()`` has already run. Early
+parameter handlers (``mem=``, ``earlycon=``, ``loglevel=``, ...) therefore
+cannot see values supplied via the embedded ``kernel`` subtree.
+
+``CONFIG_BOOT_CONFIG_EMBED_CMDLINE`` resolves this by rendering the
+``kernel`` subtree of ``CONFIG_BOOT_CONFIG_EMBED_FILE`` into a flat cmdline
+string at kernel build time (via ``tools/bootconfig -C``) and prepending
+it to ``boot_command_line`` during early architecture setup, so the keys
+are visible to ``parse_early_param()``.
+
+The option requires ``CONFIG_BOOT_CONFIG_EMBED=y``, a non-empty
+``CONFIG_BOOT_CONFIG_EMBED_FILE``, and an architecture that selects
+``CONFIG_ARCH_SUPPORTS_CMDLINE_FROM_BOOTCONFIG``. Currently only x86
+selects it; on other architectures the embedded bootconfig still works,
+but only through the late runtime parser.
+
+The same ``bootconfig`` opt-in applies as elsewhere: the rendered keys
+are prepended only when ``bootconfig`` (in any form) appears on the
+kernel command line, or when ``CONFIG_BOOT_CONFIG_FORCE`` is set, which
+defaults to ``y`` when ``CONFIG_BOOT_CONFIG_EMBED`` is set.
+
+For example, given::
+
+ kernel {
+   loglevel = 7
+   mem = 4G
+ }
+
+the kernel boots as if ``loglevel=7 mem=4G`` had been prepended to the
+bootloader command line, with the values visible to early-parsed
+handlers. Comma-separated values are still expanded into multiple
+cmdline entries per the bootconfig array convention -- the embedded
+``kernel.earlycon = "uart8250,io,0x3f8"`` must be quoted to land as a
+single ``earlycon=`` entry, exactly as for the runtime parser.
+
+If an initrd carries its own bootconfig, the runtime parser still
+processes it; ``parse_args()`` last-wins means the initrd's ``kernel``
+keys override the build-time-rendered ones. If the rendered string
+would not fit in ``COMMAND_LINE_SIZE`` together with the existing
+command line, the prepend is skipped and an error is logged, so an
+oversized embedded bootconfig cannot brick a boot.
+
 Kernel parameters via Boot Config
 =================================
 
Signature · 1 line
2.53.0-Meta
#15 lore raw

PATCH v4 7/7 x86/setup: prepend embedded bootconfig cmdline before parse_early_param

In reply to Breno Leitao

Call xbc_prepend_embedded_cmdline() in setup_arch() right after the CONFIG_CMDLINE merge and before strscpy(command_line, ...) so the build-time-rendered embedded bootconfig "kernel" subtree is part of boot_command_line by the time parse_early_param() runs. early_param() handlers (mem=, earlycon=, loglevel=, ...) now see values supplied via CONFIG_BOOT_CONFIG_EMBED_FILE without parsing bootconfig at runtime.

Gate the prepend on the same opt-in the runtime parser uses: prepend when "bootconfig" is present on the command line, or when CONFIG_BOOT_CONFIG_FORCE is set. setup_boot_config()'s parse_args() loop treats any presence of the "bootconfig" key as opt-in regardless of value, so check both cmdline_find_option_bool() (matches the bare key) and cmdline_find_option() (matches "bootconfig=<anything>"). Without the latter check, "bootconfig=0" would skip the early prepend yet still trigger the late runtime apply, leaving the embedded keys invisible to early_param() but applied to saved_command_line.

---
 arch/x86/Kconfig        |  1 +
 arch/x86/kernel/setup.c | 27 +++++++++++++++++++++++++++
 init/main.c             | 25 ++++++++++++++++++++++---
 3 files changed, 50 insertions(+), 3 deletions(-)
arch/x86/Kconfig +1 -0
index 0de23e647197..8ab11199c16d 100644
@@ -127,6 +127,7 @@ config X86
 	select ARCH_SUPPORTS_NUMA_BALANCING	if X86_64
 	select ARCH_SUPPORTS_KMAP_LOCAL_FORCE_MAP	if NR_CPUS <= 4096
 	select ARCH_SUPPORTS_CFI		if X86_64
+	select ARCH_SUPPORTS_CMDLINE_FROM_BOOTCONFIG
 	select ARCH_USES_CFI_TRAPS		if X86_64 && CFI
 	select ARCH_SUPPORTS_LTO_CLANG
 	select ARCH_SUPPORTS_LTO_CLANG_THIN
arch/x86/kernel/setup.c +27 -0
index 46882ce79c3a..d69ba84c203f 100644
@@ -6,6 +6,7 @@
  * parts of early kernel initialization.
  */
 #include <linux/acpi.h>
+#include <linux/bootconfig.h>
 #include <linux/console.h>
 #include <linux/cpu.h>
 #include <linux/crash_dump.h>
@@ -36,6 +37,7 @@
 #include <asm/bios_ebda.h>
 #include <asm/bugs.h>
 #include <asm/cacheinfo.h>
+#include <asm/cmdline.h>
 #include <asm/coco.h>
 #include <asm/cpu.h>
 #include <asm/efi.h>
@@ -924,6 +926,31 @@ void __init setup_arch(char **cmdline_p)
 	builtin_cmdline_added = true;
 #endif
 
+	/*
+	 * Match the runtime bootconfig parser's opt-in: only fold the
+	 * embedded kernel.* keys into the cmdline when "bootconfig" is
+	 * present on the command line, or CONFIG_BOOT_CONFIG_FORCE is set.
+	 * setup_boot_config()'s parse_args() loop treats any presence of
+	 * the "bootconfig" key as opt-in (bare, =0, =1, ...), so check both
+	 * forms here: cmdline_find_option_bool() matches the bare key,
+	 * cmdline_find_option() matches "bootconfig=<anything>". Without
+	 * the second check, "bootconfig=0" would skip the early prepend
+	 * but still trigger the late runtime apply -- a split-brain state.
+	 * CONFIG_BOOT_CONFIG_FORCE defaults to y when BOOT_CONFIG_EMBED is
+	 * set, so on the default config the embedded keys are applied
+	 * unconditionally.
+	 */
+	{
+		char buf[8];
+
+		if (IS_ENABLED(CONFIG_BOOT_CONFIG_FORCE) ||
+		    cmdline_find_option_bool(boot_command_line, "bootconfig") ||
+		    cmdline_find_option(boot_command_line, "bootconfig",
+					buf, sizeof(buf)) >= 0)
+			xbc_prepend_embedded_cmdline(boot_command_line,
+						     COMMAND_LINE_SIZE);
+	}
+
 	strscpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
 	*cmdline_p = command_line;
 
init/main.c +22 -3
index e363232b428b..2ecb6aa536dd 100644
@@ -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_BOOT_CONFIG_EMBED_CMDLINE 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");
 	}
Signature · 1 line
2.53.0-Meta
#16 lore raw

Re: [PATCH v4 7/7] x86/setup: prepend embedded bootconfig cmdline before parse_early_param

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Embedded bootconfig parameters leak into the kernel command line when an initrd bootconfig is…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Embedded bootconfig parameters leak into the kernel command line when an initrd bootconfig is provided, violating the override priority and creating duplicate keys. --

commit 9c00cec56ea23ba4a68bbf333ebf81d192d7c851
Author: Breno Leitao <[email protected]>

x86/setup: prepend embedded bootconfig cmdline before parse_early_param

This commit modifies setup_arch() to fold the embedded bootconfig "kernel" subtree into the boot_command_line early. This allows early_param() handlers to see values supplied via the embedded bootconfig without parsing bootconfig at runtime.

Quoted 3 lines
arch/x86/kernel/setup.c +0 -0

[ ... ]

Quoted 6 lines
arch/x86/kernel/setup.c +2 -0
@@ -924,6 +926,31 @@ void __init setup_arch(char **cmdline_p)
 	builtin_cmdline_added = true;
 #endif
 
+	/*
+	 * Match the runtime bootconfig parser's opt-in: only fold the

[ ... ]

arch/x86/kernel/setup.c void __init setup_arch(char **cmdline_p) · line 951

Quoted 11 lines
arch/x86/kernel/setup.c +11 -0
+	 * unconditionally.
+	 */
+	{
+		char buf[8];
+
+		if (IS_ENABLED(CONFIG_BOOT_CONFIG_FORCE) ||
+		    cmdline_find_option_bool(boot_command_line, "bootconfig") ||
+		    cmdline_find_option(boot_command_line, "bootconfig",
+					buf, sizeof(buf)) >= 0)
+			xbc_prepend_embedded_cmdline(boot_command_line,
+						     COMMAND_LINE_SIZE);

[Severity: High]
If an initrd bootconfig is present, does prepending the embedded bootconfig here in setup_arch() defeat the ability for the initrd bootconfig to override it?

Because the embedded bootconfig is prepended to boot_command_line before the initrd is checked, early parameters (like mem= or earlycon=) will only ever see the embedded bootconfig values.

Quoted 8 lines
arch/x86/kernel/setup.c +2 -0
+	}
+
 	strscpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
 	*cmdline_p = command_line;
init/main.c +0 -0

[ ... ]

Quoted 4 lines
init/main.c +0 -0
@@ -378,12 +378,15 @@ static void __init setup_boot_config(void)
 	int pos, ret;
 	size_t size;
 	char *err;

init/main.c static void __init setup_boot_config(void) · line 389

Quoted 10 lines
init/main.c +4 -1
+	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;
+	}

[Severity: High]
When setup_boot_config() discovers an initrd bootconfig, data will be non-NULL and from_embedded will be false.

Won't this lead to extra_command_line containing the initrd keys, while boot_command_line already contains the embedded keys prepended earlier?

This seems like it would cause both sets of keys to be merged into saved_command_line, potentially creating conflicting or duplicate arguments. Is there a way to defer or override the embedded keys if an initrd bootconfig is provided?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
#4 lore raw

Re: [PATCH v4 3/7] bootconfig: render embedded bootconfig as a kernel cmdline at build time

In reply to Breno Leitao

init/Kconfig config BOOT_CONFIG_EMBED_FILE · line 1582

Quoted 2 lines · Breno Leitao
init/Kconfig +2 -0
+	depends on BOOT_CONFIG_EMBED
+	depends on BOOT_CONFIG_EMBED_FILE != ""

Hi Breno,

Just an FYI, this dependency on BOOT_CONFIG_EMBED is redundant because the:
BOOT_CONFIG_EMBED_FILE != ""
is only possible when BOOT_CONFIG_EMBED is enabled.

- Julian Braha

#9 lore raw

Re: [PATCH v4 6/7] Documentation: bootconfig: document build-time cmdline rendering

In reply to Breno Leitao
Quoted 7 lines · On Tue, 09 Jun 2026 03:28:33 -0700 Breno Leitao <[email protected]> wrote:

Add a section describing CONFIG_BOOT_CONFIG_EMBED_CMDLINE: what it does (renders the embedded "kernel" subtree to a flat cmdline at build time so early_param() handlers see the values), what it requires (BOOT_CONFIG_EMBED, a non-empty BOOT_CONFIG_EMBED_FILE, and ARCH_SUPPORTS_CMDLINE_FROM_BOOTCONFIG -- currently x86 only), the bootconfig opt-in semantics, the initrd-vs-embedded precedence, and the soft-error overflow behavior.

Hi Breno,

Thanks for adding the document. But related to the Sashiko's comment, I believe it's necessary to pre-describe in this document how the kernel behaves with various combinations of cmdline and bootconfig, both embbedded and initrd/bootloader.

We can have these ways to pass the kernel options.

- bootloader cmdline
- embedded cmdline
- initrd bootconfig
- embedded bootconfig (standard/cmdline)

Clearly, we will have the option to choose between a standard embedded boot configuration or a command-line one, not either, but the behavior is different. I confirmed that is covered.

Embedded bootconfig is a kind of default bootconfig, which is NOT used when initrd has another bootconfig. I made this design because of /proc/bootconfig, which is not merged with embedded one. However, CONFIG_BOOT_CONFIG_EMBED_CMDLINE will be a bit different, if it is embedded and "bootconfig" feature is enabled, the embbedded one has been used already.

To avoid confusion, when this option is used, shouldn't we treat it the same way as if embedded command lines were enabled, and either not display it in /proc/bootconfig (or always display it, by merging the rendered string)?

Thank you,

Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>
#5 lore raw

Re: [PATCH v4 3/7] bootconfig: render embedded bootconfig as a kernel cmdline at build time

In reply to Julian Braha

Hello Julian,

Quoted 10 lines · Julian Braha

init/Kconfig config BOOT_CONFIG_EMBED_FILE · line 1582

Quoted 2 lines · Breno Leitao
init/Kconfig +2 -0
+	depends on BOOT_CONFIG_EMBED
+	depends on BOOT_CONFIG_EMBED_FILE != ""

Hi Breno,

Just an FYI, this dependency on BOOT_CONFIG_EMBED is redundant because the:
BOOT_CONFIG_EMBED_FILE != ""
is only possible when BOOT_CONFIG_EMBED is enabled.

Good catch, thanks. BOOT_CONFIG_EMBED_FILE itself already depends on BOOT_CONFIG_EMBED, so the explicit line is redundant. I'll drop it!

Thanks for the review,
--breno

#10 lore raw

Re: [PATCH v4 6/7] Documentation: bootconfig: document build-time cmdline rendering

In reply to Masami Hiramatsu (Google)
Quoted 18 lines · Masami Hiramatsu
Quoted 7 lines · On Tue, 09 Jun 2026 03:28:33 -0700 Breno Leitao <[email protected]> wrote:

Add a section describing CONFIG_BOOT_CONFIG_EMBED_CMDLINE: what it does (renders the embedded "kernel" subtree to a flat cmdline at build time so early_param() handlers see the values), what it requires (BOOT_CONFIG_EMBED, a non-empty BOOT_CONFIG_EMBED_FILE, and ARCH_SUPPORTS_CMDLINE_FROM_BOOTCONFIG -- currently x86 only), the bootconfig opt-in semantics, the initrd-vs-embedded precedence, and the soft-error overflow behavior.

Hi Breno,

Thanks for adding the document. But related to the Sashiko's comment, I believe it's necessary to pre-describe in this document how the kernel behaves with various combinations of cmdline and bootconfig, both embbedded and initrd/bootloader.

Quoted 6 lines

We can have these ways to pass the kernel options.

- bootloader cmdline
- embedded cmdline
- initrd bootconfig
- embedded bootconfig (standard/cmdline)

Will do. For v5 I'll extend bootconfig.rst with a section that walks through each combination -- which source wins, when parse_early_param() sees it, and how it shows up in /proc/cmdline and /proc/bootconfig.

Quoted 11 lines

Clearly, we will have the option to choose between a standard embedded boot configuration or a command-line one, not either, but the behavior is different. I confirmed that is covered.

Embedded bootconfig is a kind of default bootconfig, which is NOT used when initrd has another bootconfig. I made this design because of /proc/bootconfig, which is not merged with embedded one. However, CONFIG_BOOT_CONFIG_EMBED_CMDLINE will be a bit different, if it is embedded and "bootconfig" feature is enabled, the embbedded one has been used already.

Quoted 4 lines

To avoid confusion, when this option is used, shouldn't we treat it the same way as if embedded command lines were enabled, and either not display it in /proc/bootconfig (or always display it, by merging the rendered string)?

You're right that EMBED_CMDLINE breaks it: the embedded kernel.* keys are already in boot_command_line before setup_boot_config() ever sees the initrd bconf, so a user reading /proc/bootconfig would see only the initrd keys while parse_early_param() acted on the embedded ones. That's exactly the split-state Sashiko was circling around.

Both options you suggest work for me, but they pull in opposite directions and I'd rather not guess wrong on the user-facing contract. Which do you prefer for v5?

(a) Don't display embedded in /proc/bootconfig -- keep the current "file shows the active bootconfig source" behavior and document that with EMBED_CMDLINE=y, the kernel.* subtree may have been applied separately via the cmdline.

(b) Always display embedded by merging the rendered string into /proc/bootconfig when EMBED_CMDLINE=y, so the file reflects what was actually applied.

Happy to go either way

Thanks for the direction,
--breno

#11 lore raw

Re: [PATCH v4 6/7] Documentation: bootconfig: document build-time cmdline rendering

Quoted 21 lines · Breno Leitao
Quoted 4 lines · Masami Hiramatsu

To avoid confusion, when this option is used, shouldn't we treat it the same way as if embedded command lines were enabled, and either not display it in /proc/bootconfig (or always display it, by merging the rendered string)?

You're right that EMBED_CMDLINE breaks it: the embedded kernel.* keys are already in boot_command_line before setup_boot_config() ever sees the initrd bconf, so a user reading /proc/bootconfig would see only the initrd keys while parse_early_param() acted on the embedded ones. That's exactly the split-state Sashiko was circling around.

Both options you suggest work for me, but they pull in opposite directions and I'd rather not guess wrong on the user-facing contract. Which do you prefer for v5?

(a) Don't display embedded in /proc/bootconfig -- keep the current "file shows the active bootconfig source" behavior and document that with EMBED_CMDLINE=y, the kernel.* subtree may have been applied separately via the cmdline.

Quoted 5 lines

(b) Always display embedded by merging the rendered string into /proc/bootconfig when EMBED_CMDLINE=y, so the file reflects what was actually applied.

Happy to go either way

Following up on my own mail rather than leaving it fully open: after looking at the code more, I'd like to recommend (a).

The deciding factor is ordering. EMBED_CMDLINE only works because the embedded "kernel" keys are folded into boot_command_line in setup_arch(), before parse_early_param() -- which is long before setup_boot_config() looks at the initrd.

So for early params the embedded values are necessarily applied first, and an initrd bootconfig cannot override them no matter how we present /proc/bootconfig. That makes the embedded cmdline behave like a build-time CONFIG_CMDLINE rather than a bootconfig source, and (a) is the option that describes it honestly: it shows in /proc/cmdline, and /proc/bootconfig keeps meaning "the bootconfig tree that was parsed".

(a) is also what the tree already does -- saved_boot_config is built only from the XBC tree, the rendered string never enters it -- so it is no new code on the /proc side and keeps the series small.

(b) would pull the flattened cmdline string back into the structured tree view and need dedup against the initrd keys, which muddies what /proc/bootconfig means for little gain.

So unless you'd rather have (b), I'll take (a) for v5 and extend bootconfig.rst to cover the four sources (bootloader cmdline, embedded cmdline, initrd bootconfig, embedded bootconfig).

I'll also document the sharp edge -- with both an embedded cmdline and an initrd bootconfig, early params reflect the embedded values because the initrd is not parsed yet.

Thanks,
--breno

#12 lore raw

Re: [PATCH v4 6/7] Documentation: bootconfig: document build-time cmdline rendering

Quoted 22 lines · On Wed, 17 Jun 2026 02:56:23 -0700 Breno Leitao <[email protected]> wrote:
Quoted 21 lines · Breno Leitao
Quoted 4 lines · Masami Hiramatsu

To avoid confusion, when this option is used, shouldn't we treat it the same way as if embedded command lines were enabled, and either not display it in /proc/bootconfig (or always display it, by merging the rendered string)?

You're right that EMBED_CMDLINE breaks it: the embedded kernel.* keys are already in boot_command_line before setup_boot_config() ever sees the initrd bconf, so a user reading /proc/bootconfig would see only the initrd keys while parse_early_param() acted on the embedded ones. That's exactly the split-state Sashiko was circling around.

Both options you suggest work for me, but they pull in opposite directions and I'd rather not guess wrong on the user-facing contract. Which do you prefer for v5?

(a) Don't display embedded in /proc/bootconfig -- keep the current "file shows the active bootconfig source" behavior and document that with EMBED_CMDLINE=y, the kernel.* subtree may have been applied separately via the cmdline.

Quoted 8 lines
Quoted 5 lines

(b) Always display embedded by merging the rendered string into /proc/bootconfig when EMBED_CMDLINE=y, so the file reflects what was actually applied.

Happy to go either way

Following up on my own mail rather than leaving it fully open: after looking at the code more, I'd like to recommend (a).

Agreed. Sorry for replying late.

Quoted 5 lines

The deciding factor is ordering. EMBED_CMDLINE only works because the embedded "kernel" keys are folded into boot_command_line in setup_arch(), before parse_early_param() -- which is long before setup_boot_config() looks at the initrd.

Yes. Unless doing setup_arch() we can not get initrd image, this means we don't know whether there is bootconfig or not at that point.

Quoted 7 lines

So for early params the embedded values are necessarily applied first, and an initrd bootconfig cannot override them no matter how we present /proc/bootconfig. That makes the embedded cmdline behave like a build-time CONFIG_CMDLINE rather than a bootconfig source, and (a) is the option that describes it honestly: it shows in /proc/cmdline, and /proc/bootconfig keeps meaning "the bootconfig tree that was parsed".

Indeed. So I think this EMBED_CMDLINE is more like CMDLINE set by bootconfig file, instead of embedded string. That is useful for reusing the boot options. We need to change the explanation and clarify it.

Thus we should those configs mutual exclusive. If user already sets the CONFIG_CMDLINE, EMBED_CMDLINE should not be enabled.

But actually, there is another options we need to mention:

- CONFIG_CMDLINE: default cmdline, could be ignored if bootloader passes a cmdline string.
- CONFIG_CMDLINE_FORCE: ignore the other cmdline. (but bootconfig can overwrite it, hmm)
- CONFIG_CMDLINE_EXTEND: append the embedded cmdline string to bootloader cmdline. (similar to bootconfig current behavior)

- CONFIG_BOOT_CONFIG_EMBED: just an embedded bootconfig. extends the existing cmdline, but does not support early parameters. This is ignored if user passed bootconfig via initrd.

- CONFIG_BOOT_CONFIG_EMBED_CMDLINE: replacing CONFIG_CMDLINE with bootconfig but it will not shown in /proc/bootconfig.

So you can see CONFIG_BOOT_CONFIG_EMBED_CMDLINE is a bit special. I think it maybe natual that we call it CONFIG_CMDLINE_BOOT_CONFIG. In this case, we render the cmdline string from bootconfig build-time and set CONFIG_CMDLINE with the rendered cmdline string.

Quoted 4 lines

(a) is also what the tree already does -- saved_boot_config is built only from the XBC tree, the rendered string never enters it -- so it is no new code on the /proc side and keeps the series small.

Agreed.

Quoted 4 lines

(b) would pull the flattened cmdline string back into the structured tree view and need dedup against the initrd keys, which muddies what /proc/bootconfig means for little gain.

I would like to avoid such complexity, just keep it simple as possible.

Quoted 4 lines

So unless you'd rather have (b), I'll take (a) for v5 and extend bootconfig.rst to cover the four sources (bootloader cmdline, embedded cmdline, initrd bootconfig, embedded bootconfig).

Yes, I agree with you.

Quoted 4 lines

I'll also document the sharp edge -- with both an embedded cmdline and an initrd bootconfig, early params reflect the embedded values because the initrd is not parsed yet.

My recommendation is to give simpler mind model to users. If it is simply extend the CONFIG_CMDLINE which can be described by bootconfig file, that is more managable outside of kernel configuration.

Or, you would like to access cmdline setting via /proc/bootconfig? In this case, the problem is a bit more limitation of bootconfig side.

Since the kernel cmdline accepts any contradictory settings, if "foo=A foo=B" are passed, bootconfig will make an error because foo has 2 different settings.
Typically, this is represented as an array in bootconfig.

foo = A, B;

But if cmdline bootconfig says:

foo = A;

and initrd bootconfig says:

foo := B;

":=" means overriding the previous settings. Thus a contradiction arises between these two, when rendering /proc/bootconfig. It can not show 2 different settings for the same key. (it is possible if we render it twice, but /proc/bootconfig user may not expect it.)

I think it's fine to represent it as an array (foo = A, B) if this ENBED_CMDLINE is set, but it still seems risky if early parameters aren't detected. If early_param = A is set in the embedded bootconfig, and accidentally initrd bootconfig sets early_param = B we should ignore latter one (with warning). But maybe it is another story.

I think we can proceed it without rendering it in /proc/bootconfig at this point. And later we find the way to detect early parameters correctly, we can fix it.

(BTW, early parameter problem is a bit complicated. It is not hard to distinguish early parameters, but kernel accepts the same key for early parameter and normal parameter. e.g. "console=")

Thank you,

Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>
#13 lore raw

Re: [PATCH v4 6/7] Documentation: bootconfig: document build-time cmdline rendering

Quoted 29 lines · Masami Hiramatsu
Quoted 26 lines · On Wed, 17 Jun 2026 02:56:23 -0700 Breno Leitao <[email protected]> wrote:
Quoted 25 lines · Breno Leitao
Quoted 4 lines · Masami Hiramatsu

To avoid confusion, when this option is used, shouldn't we treat it the same way as if embedded command lines were enabled, and either not display it in /proc/bootconfig (or always display it, by merging the rendered string)?

You're right that EMBED_CMDLINE breaks it: the embedded kernel.* keys are already in boot_command_line before setup_boot_config() ever sees the initrd bconf, so a user reading /proc/bootconfig would see only the initrd keys while parse_early_param() acted on the embedded ones. That's exactly the split-state Sashiko was circling around.

Both options you suggest work for me, but they pull in opposite directions and I'd rather not guess wrong on the user-facing contract. Which do you prefer for v5?

(a) Don't display embedded in /proc/bootconfig -- keep the current "file shows the active bootconfig source" behavior and document that with EMBED_CMDLINE=y, the kernel.* subtree may have been applied separately via the cmdline.

(b) Always display embedded by merging the rendered string into /proc/bootconfig when EMBED_CMDLINE=y, so the file reflects what was actually applied.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Happy to go either way

Following up on my own mail rather than leaving it fully open: after looking at the code more, I'd like to recommend (a).

Agreed. Sorry for replying late.

No problem, thanks. Quick heads-up: v5 already went out and crossed with this mail. It takes (a) and extends bootconfig.rst to walk through the four sources (bootloader cmdline, embedded cmdline, initrd bootconfig, embedded bootconfig), so that part is already in flight:

https://lore.kernel.org/r/[email protected]

The naming/mutual-exclusion rework below I'll fold into v6.

Quoted 3 lines

Indeed. So I think this EMBED_CMDLINE is more like CMDLINE set by bootconfig file, instead of embedded string. That is useful for reusing the boot options. We need to change the explanation and clarify it.

Agreed, that's a much clearer model. v6 will reframe the Kconfig help and bootconfig.rst around "this is CONFIG_CMDLINE, sourced from a bootconfig file at build time" rather than "an embedded bootconfig that also feeds the cmdline".

It also matches what the code already does precedence-wise: the rendered "kernel" string is prepended to boot_command_line in setup_arch(), so it sits in front of the bootloader args and parse_args() last-wins lets the bootloader override it -- i.e. exactly CONFIG_CMDLINE without _OVERRIDE. So this is mostly a rename + dependency + docs change, not a behavioral one. (A _FORCE/_EXTEND-style variant could come later if there's demand; the current behavior is the plain "overridable default" one.)

Quoted 2 lines

Thus we should those configs mutual exclusive. If user already sets the CONFIG_CMDLINE, EMBED_CMDLINE should not be enabled.

Makes sense -- two built-in cmdline sources at once is confusing. I'll make them mutually exclusive in v6. I'm thinking:

depends on CMDLINE = ""

on the new symbol. On x86 CONFIG_CMDLINE is a string that depends on CMDLINE_BOOL and defaults to "", so this reads as "only offer the bootconfig-rendered cmdline when no static CONFIG_CMDLINE is configured", and it works the same on other arches that define CMDLINE as a string. Does that match what you had in mind, or would you rather gate it the other way (CMDLINE depends on !the-new-symbol)?

Quoted 8 lines

So you can see CONFIG_BOOT_CONFIG_EMBED_CMDLINE is a bit special. I think it maybe natual that we call it CONFIG_CMDLINE_BOOT_CONFIG. In this case, we render the cmdline string from bootconfig build-time and set CONFIG_CMDLINE with the rendered cmdline string. So you can see CONFIG_BOOT_CONFIG_EMBED_CMDLINE is a bit special. I think it maybe natual that we call it CONFIG_CMDLINE_BOOT_CONFIG. In this case, we render the cmdline string from bootconfig build-time and set CONFIG_CMDLINE with the rendered cmdline string.

I'll rename it for v6. One nit: the arch opt-in symbol is already ARCH_SUPPORTS_CMDLINE_FROM_BOOTCONFIG, so CONFIG_CMDLINE_FROM_BOOTCONFIG would pair with it verbatim. I'll use CONFIG_CMDLINE_FROM_BOOTCONFIG I'll rename it for v6.

Another nit: the arch opt-in symbol is already ARCH_SUPPORTS_CMDLINE_FROM_BOOTCONFIG, so CONFIG_CMDLINE_FROM_BOOTCONFIG would pair with it verbatim. I'll use CONFIG_CMDLINE_FROM_BOOTCONFIG unless you'd rather keep CONFIG_CMDLINE_BOOT_CONFIG -- either is fine by me.

One clarification on "set CONFIG_CMDLINE with the rendered string":
CONFIG_CMDLINE is a Kconfig string fixed when .config is read, while the render happens later during the build, so we can't literally store the rendered text into CONFIG_CMDLINE. The mechanism stays "render into .init.rodata, merge into boot_command_line in setup_arch()"; what changes is how we name and document it, plus the mutual exclusion above. Let me

Quoted 2 lines

So you can see CONFIG_BOOT_CONFIG_EMBED_CMDLINE is a bit special. I think it maybe natual that we call it CONFIG_CMDLINE_BOOT_CONFIG.

I'll rename it for v6. One nit: the arch opt-in symbol is already ARCH_SUPPORTS_CMDLINE_FROM_BOOTCONFIG, so CONFIG_CMDLINE_FROM_BOOTCONFIG would pair with it verbatim. I'll use CONFIG_CMDLINE_FROM_BOOTCONFIG

Quoted 2 lines

In this case, we render the cmdline string from bootconfig build-time and set CONFIG_CMDLINE with the rendered cmdline string.

CONFIG_CMDLINE is a Kconfig string fixed when .config is read, while the render happens later during the build, so we can't literally store the rendered text into CONFIG_CMDLINE? let me know if you can envision a way to get it done.

Quoted 3 lines

I think we can proceed it without rendering it in /proc/bootconfig at this point. And later we find the way to detect early parameters correctly, we can fix it.

Sounds good. I'll document the sharp edge (with both an embedded cmdline and an initrd bootconfig, early params reflect the embedded values because the initrd isn't parsed yet) and leave the early-param-aware override detection as the follow-up you describe.

Quoted 3 lines

(BTW, early parameter problem is a bit complicated. It is not hard to distinguish early parameters, but kernel accepts the same key for early parameter and normal parameter. e.g. "console=")

Right, console= being both is the awkward case. Agreed that's better as its own series once we have a reliable way to detect early params.

So the v6 plan:
- rename CONFIG_BOOT_CONFIG_EMBED_CMDLINE -> CONFIG_CMDLINE_FROM_BOOTCONFIG (or _BOOT_CONFIG, your call)
- make it mutually exclusive with CONFIG_CMDLINE (depends on CMDLINE = "")
- reframe the Kconfig help + bootconfig.rst as "CONFIG_CMDLINE from a bootconfig file"
- keep (a): no rendering in /proc/bootconfig; document the early-param sharp edge
- defer early-param-aware override detection to a follow-up

Thanks for the direction,
--breno

#14 lore raw

Re: [PATCH v4 6/7] Documentation: bootconfig: document build-time cmdline rendering

Hi Breno,

Quoted 37 lines · On Mon, 22 Jun 2026 05:30:53 -0700 Breno Leitao <[email protected]> wrote:
Quoted 29 lines · Masami Hiramatsu
Quoted 26 lines · On Wed, 17 Jun 2026 02:56:23 -0700 Breno Leitao <[email protected]> wrote:
Quoted 25 lines · Breno Leitao
Quoted 4 lines · Masami Hiramatsu

To avoid confusion, when this option is used, shouldn't we treat it the same way as if embedded command lines were enabled, and either not display it in /proc/bootconfig (or always display it, by merging the rendered string)?

You're right that EMBED_CMDLINE breaks it: the embedded kernel.* keys are already in boot_command_line before setup_boot_config() ever sees the initrd bconf, so a user reading /proc/bootconfig would see only the initrd keys while parse_early_param() acted on the embedded ones. That's exactly the split-state Sashiko was circling around.

Both options you suggest work for me, but they pull in opposite directions and I'd rather not guess wrong on the user-facing contract. Which do you prefer for v5?

(a) Don't display embedded in /proc/bootconfig -- keep the current "file shows the active bootconfig source" behavior and document that with EMBED_CMDLINE=y, the kernel.* subtree may have been applied separately via the cmdline.

(b) Always display embedded by merging the rendered string into /proc/bootconfig when EMBED_CMDLINE=y, so the file reflects what was actually applied.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Happy to go either way

Following up on my own mail rather than leaving it fully open: after looking at the code more, I'd like to recommend (a).

Agreed. Sorry for replying late.

Quoted 8 lines

No problem, thanks. Quick heads-up: v5 already went out and crossed with this mail. It takes (a) and extends bootconfig.rst to walk through the four sources (bootloader cmdline, embedded cmdline, initrd bootconfig, embedded bootconfig), so that part is already in flight:

https://lore.kernel.org/r/[email protected]

The naming/mutual-exclusion rework below I'll fold into v6.

Yeah, thanks for updating!

Quoted 9 lines
Quoted 4 lines

Indeed. So I think this EMBED_CMDLINE is more like CMDLINE set by bootconfig file, instead of embedded string. That is useful for reusing the boot options. We need to change the explanation and clarify it.

Agreed, that's a much clearer model. v6 will reframe the Kconfig help and bootconfig.rst around "this is CONFIG_CMDLINE, sourced from a bootconfig file at build time" rather than "an embedded bootconfig that also feeds the cmdline".

Nice!

Quoted 8 lines

It also matches what the code already does precedence-wise: the rendered "kernel" string is prepended to boot_command_line in setup_arch(), so it sits in front of the bootloader args and parse_args() last-wins lets the bootloader override it -- i.e. exactly CONFIG_CMDLINE without _OVERRIDE. So this is mostly a rename + dependency + docs change, not a behavioral one. (A _FORCE/_EXTEND-style variant could come later if there's demand; the current behavior is the plain "overridable default" one.)

OK. Yeah, for the first step, I think current behavior is enough.

Quoted 7 lines
Quoted 3 lines

Thus we should those configs mutual exclusive. If user already sets the CONFIG_CMDLINE, EMBED_CMDLINE should not be enabled.

Makes sense -- two built-in cmdline sources at once is confusing. I'll make them mutually exclusive in v6. I'm thinking:

Quoted 8 lines

depends on CMDLINE = ""

on the new symbol. On x86 CONFIG_CMDLINE is a string that depends on CMDLINE_BOOL and defaults to "", so this reads as "only offer the bootconfig-rendered cmdline when no static CONFIG_CMDLINE is configured", and it works the same on other arches that define CMDLINE as a string. Does that match what you had in mind, or would you rather gate it the other way (CMDLINE depends on !the-new-symbol)?

No, this looks good and enough clear to me.

Quoted 10 lines
Quoted 9 lines

So you can see CONFIG_BOOT_CONFIG_EMBED_CMDLINE is a bit special. I think it maybe natual that we call it CONFIG_CMDLINE_BOOT_CONFIG. In this case, we render the cmdline string from bootconfig build-time and set CONFIG_CMDLINE with the rendered cmdline string. So you can see CONFIG_BOOT_CONFIG_EMBED_CMDLINE is a bit special. I think it maybe natual that we call it CONFIG_CMDLINE_BOOT_CONFIG. In this case, we render the cmdline string from bootconfig build-time and set CONFIG_CMDLINE with the rendered cmdline string.

Quoted 4 lines

I'll rename it for v6. One nit: the arch opt-in symbol is already ARCH_SUPPORTS_CMDLINE_FROM_BOOTCONFIG, so CONFIG_CMDLINE_FROM_BOOTCONFIG would pair with it verbatim. I'll use CONFIG_CMDLINE_FROM_BOOTCONFIG I'll rename it for v6.

Yeah, thanks!

Quoted 5 lines

Another nit: the arch opt-in symbol is already ARCH_SUPPORTS_CMDLINE_FROM_BOOTCONFIG, so CONFIG_CMDLINE_FROM_BOOTCONFIG would pair with it verbatim. I'll use CONFIG_CMDLINE_FROM_BOOTCONFIG unless you'd rather keep CONFIG_CMDLINE_BOOT_CONFIG -- either is fine by me.

I think it should use the same pattern to avoid confusion.

Quoted 7 lines

One clarification on "set CONFIG_CMDLINE with the rendered string":
CONFIG_CMDLINE is a Kconfig string fixed when .config is read, while the render happens later during the build, so we can't literally store the rendered text into CONFIG_CMDLINE. The mechanism stays "render into .init.rodata, merge into boot_command_line in setup_arch()"; what changes is how we name and document it, plus the mutual exclusion above. Let me

Yes, it is fine to me because it does not change the current behavior.

Quoted 7 lines
Quoted 3 lines

So you can see CONFIG_BOOT_CONFIG_EMBED_CMDLINE is a bit special. I think it maybe natual that we call it CONFIG_CMDLINE_BOOT_CONFIG.

I'll rename it for v6. One nit: the arch opt-in symbol is already ARCH_SUPPORTS_CMDLINE_FROM_BOOTCONFIG, so CONFIG_CMDLINE_FROM_BOOTCONFIG would pair with it verbatim. I'll use CONFIG_CMDLINE_FROM_BOOTCONFIG

Yes, that's better to be renamed.

Quoted 7 lines
Quoted 2 lines

In this case, we render the cmdline string from bootconfig build-time and set CONFIG_CMDLINE with the rendered cmdline string.

CONFIG_CMDLINE is a Kconfig string fixed when .config is read, while the render happens later during the build, so we can't literally store the rendered text into CONFIG_CMDLINE? let me know if you can envision a way to get it done.

Ah, ok. Nevermind, as far as it is shown in /proc/cmdline, I think it is OK. (BTW, if we use the embedded bootconfig, the file path is shown in
/proc/config.gz, maybe I need to notice it.)

Quoted 8 lines
Quoted 3 lines

I think we can proceed it without rendering it in /proc/bootconfig at this point. And later we find the way to detect early parameters correctly, we can fix it.

Sounds good. I'll document the sharp edge (with both an embedded cmdline and an initrd bootconfig, early params reflect the embedded values because the initrd isn't parsed yet) and leave the early-param-aware override detection as the follow-up you describe.

Thanks for the documenting :)

Quoted 18 lines
Quoted 4 lines

(BTW, early parameter problem is a bit complicated. It is not hard to distinguish early parameters, but kernel accepts the same key for early parameter and normal parameter. e.g. "console=")

Right, console= being both is the awkward case. Agreed that's better as its own series once we have a reliable way to detect early params.

So the v6 plan:
- rename CONFIG_BOOT_CONFIG_EMBED_CMDLINE -> CONFIG_CMDLINE_FROM_BOOTCONFIG (or _BOOT_CONFIG, your call)
- make it mutually exclusive with CONFIG_CMDLINE (depends on CMDLINE = "")
- reframe the Kconfig help + bootconfig.rst as "CONFIG_CMDLINE from a bootconfig file"
- keep (a): no rendering in /proc/bootconfig; document the early-param sharp edge
- defer early-param-aware override detection to a follow-up

Quoted 1 line

Thanks for the direction,

Thanks for working on this feature!

Thank you,

Quoted 2 lines

--breno

Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>