Re: [PATCH v2 6/6] x86/setup: prepend embedded bootconfig cmdline before parse_early_param

Breno Leitao <[email protected]>
Newsgroups org.kernel.vger.linux-kbuild,org.kernel.vger.bpf,org.kernel.vger.linux-kernel,org.kernel.vger.linux-trace-kernel
Message-ID <[email protected]>
On Mon, Jun 08, 2026 at 07:19:28PM +0900, Masami Hiramatsu wrote:
> On Fri, 05 Jun 2026 05:03:37 -0700
> Breno Leitao <[email protected]> wrote:
> 
> > 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 bootconfig opt-in: only fold in the embedded
> > kernel.* keys when "bootconfig" is present on the command line, or
> > CONFIG_BOOT_CONFIG_FORCE is set. Applying the embedded cmdline
> > unconditionally would (a) diverge from how embedded init.* keys are
> > treated and (b) break fail-safe recovery: a malformed embedded
> > console=/mem= could panic the boot with no way for the admin to disable
> > it by dropping "bootconfig" from the bootloader cmdline.
> > cmdline_find_option_bool() runs before parse_early_param(), so the gate
> > is cheap and correctly ordered.
> > 
> > Select ARCH_SUPPORTS_CMDLINE_FROM_BOOTCONFIG so the user-visible
> > CONFIG_BOOT_CONFIG_EMBED_CMDLINE option becomes selectable on x86.
> 
> This seems like a dummy config. what code does depend on this flag?

No C code reads ARCH_SUPPORTS_CMDLINE_FROM_BOOTCONFIG directly — it's
a silent gating symbol, the same ARCH_SUPPORTS_* idiom as
ARCH_SUPPORTS_CFI, ARCH_SUPPORTS_LTO_CLANG, etc.

Its only role is the depends on line of BOOT_CONFIG_EMBED_CMDLINE: an
arch selects it once its setup_arch() calls
xbc_prepend_embedded_cmdline(), and that makes the user-visible
BOOT_CONFIG_EMBED_CMDLINE selectable.

Right now, only x86 supports embedded bootconfig, thus, only x86 does
the following (last patch):

	config X86
	+       select ARCH_SUPPORTS_CMDLINE_FROM_BOOTCONFIG

So, no other platform can see CONFIG_BOOT_CONFIG_EMBED_CMDLINE.

> > --- a/init/main.c
> > +++ b/init/main.c
> > @@ -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;
> 
> Even from embedded bootconfig, if the arch set 
> ARCH_SUPPORTS_CMDLINE_FROM_BOOTCONFIG=n, this must be applied to
> the cmdline as we are doing.

Right — that path is preserved. When the arch doesn't select
ARCH_SUPPORTS_CMDLINE_FROM_BOOTCONFIG, BOOT_CONFIG_EMBED_CMDLINE is
unselectable, so xbc_embedded_cmdline_applied() is the no-op stub
returning false.

> >  	strscpy(tmp_cmdline, boot_command_line, COMMAND_LINE_SIZE);
> >  	err = parse_args("bootconfig", tmp_cmdline, NULL, 0, 0, 0, NULL,
> > @@ -421,8 +424,17 @@ 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.
> 
> Also, this should mention ARCH_SUPPORTS_CMDLINE_FROM_BOOTCONFIG=n case.

Ack, I will update

Thanks for the review,
--breno
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.