Skip to content

bootconfig: embed kernel.* cmdline at build time

Breno Leitao bpf linux-doc linux-kbuild linux-trace-kernel lkml llvm 8 versions – In review

Get series with b4
b4 am [email protected] change-id 20260508-bootconfig_using_tools-cfa7aa9d6a5a

Versions newest first

  1. v7 Latest9 patches 3 repliesIn review
  2. v68 patches 3 repliesSuperseded
  3. v57 patches 2 repliesSuperseded
Earlier versions · 5
VersionPostedPatchesRepliesStatus
v47 patches8 repliesSuperseded
v36 patches2 repliesSuperseded
v26 patches4 repliesSuperseded
v1 posting 2/24 patches5 repliesSuperseded
v1 posting 1/22 patches5 repliesSuperseded

Changes in v7 from the cover letter

- The runtime opt-in now shares one helper instead of open-coding its
own. (Masami)
- bootconfig_cmdline_requested() moved into generic lib code (Masami)
- Link to v6: https://lore.kernel.org/r/[email protected]

Patches in v7 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/9bootconfig: fix NULL-pointer arithmetic in xbc_snprint_cmdline()lib/bootconfig.c+16 -70 replies
2/9bootconfig: render descendant keys when xbc_snprint_cmdline() root has a valuelib/bootconfig.c+11 -00 replies
3/9bootconfig: render embedded bootconfig as a kernel cmdline at build timeMAINTAINERS Makefile init/Kconfig +3 more+86 -10 replies
4/9bootconfig: clean build-time tools/bootconfig from make cleanMakefile tools/bootconfig/Makefile+11 -20 replies
5/9bootconfig: add xbc_prepend_embedded_cmdline() helperinclude/linux/bootconfig.h lib/bootconfig.c+141 -10 replies
6/9Documentation: bootconfig: document build-time cmdline renderingDocumentation/admin-guide/bootconfig.rst+81 -00 replies
7/9x86/setup: prepend embedded bootconfig cmdline before parse_early_paramarch/x86/Kconfig arch/x86/kernel/setup.c+14 -10 replies
8/9bootconfig: skip runtime kernel.* render once prepended earlyinit/main.c+22 -30 replies
9/9init/main.c: use bootconfig_cmdline_requested() for the runtime opt-ininit/main.c+6 -210 replies

Reviews trailers per patch

2 of 9 patches have a Reviewed-by or Acked-by.

PatchNicolas Schier
1/9
2/9
3/9R-b
4/9R-b
5/9
6/9
7/9
8/9
9/9

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v7 thread

Cover letter [PATCH v7 0/9] 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 v7:
- The runtime opt-in now shares one helper instead of open-coding its
own. (Masami)
- bootconfig_cmdline_requested() moved into generic lib code (Masami)
- Link to v6: https://lore.kernel.org/r/[email protected]

Changes in v6:
- renamed CONFIG_BOOT_CONFIG_EMBED_CMDLINE to
CONFIG_CMDLINE_FROM_BOOTCONFIG
- prepend embedded bootconfig cmdline before parse_early_param
- Link to v5: https://lore.kernel.org/r/[email protected]

Changes in v5:
- Patch 3 (Kconfig): drop the redundant "depends on BOOT_CONFIG_EMBED"
from CMDLINE_FROM_BOOTCONFIG; Julian Braha.
- Patch 6 (Documentation): spell out how the embedded cmdline interacts
with the bootloader cmdline, an initrd bootconfig, and the embedded
bootconfig
- Link to v4: https://lore.kernel.org/r/[email protected]

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_CMDLINE_FROM_BOOTCONFIG 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 (9):
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
bootconfig: skip runtime kernel.* render once prepended early init/main.c: use bootconfig_cmdline_requested() for the runtime opt-in

 Documentation/admin-guide/bootconfig.rst |  81 ++++++++++++++++
 MAINTAINERS                              |   1 +
 Makefile                                 |  27 +++++-
 arch/x86/Kconfig                         |   1 +
 arch/x86/kernel/setup.c                  |  14 ++-
 include/linux/bootconfig.h               |  14 +++
 init/Kconfig                             |  36 +++++++
 init/main.c                              |  52 +++++-----
 lib/Makefile                             |  16 +++
 lib/bootconfig.c                         | 162 +++++++++++++++++++++++++++++--
 lib/embedded-cmdline.S                   |  16 +++
 tools/bootconfig/Makefile                |   4 +-
 12 files changed, 388 insertions(+), 36 deletions(-)

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

Best regards,

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