Re: [PATCH 2/3] init: use static buffers for bootconfig extra command line

From: Google

Date: Thu Apr 16 2026 - 21:45:14 EST


On Wed, 15 Apr 2026 03:51:11 -0700
Breno Leitao <leitao@xxxxxxxxxx> wrote:

> Replace memblock_alloc/memblock_free in xbc_make_cmdline() with
> static __initdata buffers. This removes the last memblock dependency
> from the bootconfig loading path, completing the prerequisite for
> running bootconfig parsing before memblock is available.
>
> Signed-off-by: Breno Leitao <leitao@xxxxxxxxxx>
> ---
> init/main.c | 24 ++++++++++++------------
> 1 file changed, 12 insertions(+), 12 deletions(-)
>
> diff --git a/init/main.c b/init/main.c
> index 96f93bb06c490..b9feca55e01f9 100644
> --- a/init/main.c
> +++ b/init/main.c
> @@ -369,11 +369,18 @@ static int __init xbc_snprint_cmdline(char *buf, size_t size,
> }
> #undef rest
>
> +/*
> + * Static buffers for bootconfig-generated command line parameters.
> + * Two separate buffers are needed because both "kernel" and "init"
> + * parameters are stored simultaneously.
> + */
> +static char extra_cmdline_buf[COMMAND_LINE_SIZE] __initdata;
> +static char extra_initargs_buf[COMMAND_LINE_SIZE] __initdata;

This is not good to me, since bootconfig supports bigger config file
than COMMAND_LINE_SIZE. Even if we limits the size for embedded
bootconfig file, it should depends on CONFIG_BOOT_CONFIG_EMBED.

Please use XBC_DATA_MAX instead of COMMAND_LINE_SIZE, or calculate
expected data length when compiling kernel.

But if we can do it, should we continue using bootconfig? I mean
it is easy to make a tool (or add a feature in tools/bootconfig)
which converts bootconfig file to command line string and embeds
it in the kernel. Hmm.

Thanks,

> +
> /* Make an extra command line under given key word */
> -static char * __init xbc_make_cmdline(const char *key)
> +static char * __init xbc_make_cmdline(const char *key, char *new_cmdline)
> {
> struct xbc_node *root;
> - char *new_cmdline;
> int ret, len = 0;
>
> root = xbc_find_node(key);
> @@ -382,19 +389,12 @@ static char * __init xbc_make_cmdline(const char *key)
>
> /* Count required buffer size */
> len = xbc_snprint_cmdline(NULL, 0, root);
> - if (len <= 0)
> + if (len <= 0 || len >= COMMAND_LINE_SIZE)
> return NULL;
>
> - new_cmdline = memblock_alloc(len + 1, SMP_CACHE_BYTES);
> - if (!new_cmdline) {
> - pr_err("Failed to allocate memory for extra kernel cmdline.\n");
> - return NULL;
> - }
> -
> ret = xbc_snprint_cmdline(new_cmdline, len + 1, root);
> if (ret < 0 || ret > len) {
> pr_err("Failed to print extra kernel cmdline.\n");
> - memblock_free(new_cmdline, len + 1);
> return NULL;
> }
>
> @@ -467,9 +467,9 @@ static void __init setup_boot_config(void)
> 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");
> + extra_command_line = xbc_make_cmdline("kernel", extra_cmdline_buf);
> /* Also, "init." keys are init arguments */
> - extra_init_args = xbc_make_cmdline("init");
> + extra_init_args = xbc_make_cmdline("init", extra_initargs_buf);
> }
> return;
> }
>
> --
> 2.52.0
>


--
Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>