Linux Trace Kernel
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Masami Hiramatsu (Google)" <mhiramat@kernel.org>,
	linux-trace-kernel@vger.kernel.org
Subject: Re: [RFC PATCH 2/5] bootconfig: Support stacked initrd bootconfigs and bootconfig= selection
Date: Fri, 27 Nov 2026 15:11:05 +0000	[thread overview]
Message-ID: <sashiko-outbox-237682@kernel.org> (raw)
In-Reply-To: <20261127144614.61194-3-mhiramat@kernel.org>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] bootconfig: unmatched bootconfig= selector bypasses
  CONFIG_BOOT_CONFIG_FORCE
- [Low] bootconfig: wrong config blamed for unclosed brace in
  xbc_parse_tree()
--

commit d486115d0ecb79c7d4d59dbde4c3a203ebf39848
Author: Masami Hiramatsu (Google) <mhiramat@kernel.org>

bootconfig: Support stacked initrd bootconfigs and bootconfig= selection

This commit adds support for unpacking up to 32 stacked bootconfig trailers
from an initrd image and selecting which entries to merge via the
bootconfig= kernel command-line parameter.

> diff --git a/init/main.c b/init/main.c
> index f147803450513..a539eb5b0cd12 100644
> --- a/init/main.c
> +++ b/init/main.c
[ ... ]
> @@ -475,16 +575,35 @@ static void __init setup_boot_config(void)
>  		return;
>  	}
>  
> -	ret = xbc_init(data, size, &msg, &pos);
> +	report_bad_boot_configs(cfgs, count, total);
> +
> +	if (!bootconfig_found && IS_ENABLED(CONFIG_BOOT_CONFIG_FORCE))
> +		cfgs[0].enabled = true;
> +
> +	for (i = 0; i < count; i++) {
> +		if (cfgs[i].enabled && cfgs[i].data) {
> +			any_enabled = true;
> +			break;
> +		}
> +	}
> +	if (!any_enabled)
> +		return;
> +
> +	ret = xbc_init_configs(cfgs, count, &msg, &pos, &err_idx);
>  	if (ret < 0) {
> -		if (pos < 0)
> +		if (err_idx >= 0)
> +			pr_err("Failed to parse bootconfig [%d%s%.*s]: %s at %d.\n",
> +			       err_idx, cfgs[err_idx].name_len ? ":" : "",
> +			       (int)cfgs[err_idx].name_len,
> +			       cfgs[err_idx].name, msg, pos);

[Severity: Low]
Can this blame an earlier bootconfig block when a later overlay leaves a
brace unclosed on an existing key?

When an overlay reopens a key that was already created by an earlier
block, __xbc_add_key() reuses the existing xbc_node via find_match_node()
and __xbc_open_brace() pushes that node's index onto open_brace[].  If the
brace is left unclosed at the end of the overlay, xbc_parse_tree() reports
the error at xbc_node_get_data(n):

lib/bootconfig.c:xbc_parse_tree() {
    ...
	if (!ret && brace_index) {
		n = &xbc_nodes[open_brace[brace_index - 1]];
		ret = xbc_parse_error("Brace is not closed",
				      xbc_node_get_data(n));
	}
    ...
}

Because xbc_node_get_data(n) points into the slice that first defined the
key, xbc_init_configs() maps xbc_err_pos back to that earlier block's
err_idx and byte offset.

> diff --git a/lib/bootconfig.c b/lib/bootconfig.c
> index fe27e72c9ee54..44177b7c08660 100644
> --- a/lib/bootconfig.c
> +++ b/lib/bootconfig.c
> @@ -115,33 +115,54 @@ bool __init xbc_embedded_cmdline_applied(void)
>  }
>  #endif	/* CONFIG_CMDLINE_FROM_BOOTCONFIG */
>  
> -/* parse_args() callback: flag when the "bootconfig" parameter is present. */
> -static int __init bootconfig_optin(char *param, char *val,
> -				   const char *unused, void *arg)
> +struct xbc_cmdline_select_ctx {
> +	struct xbc_config *cfgs;
> +	int count;
> +	bool seen;
> +	bool active;
> +	bool warn;
> +};
> +
> +/* parse_args() callback: track opt-in and update enabled bootconfig entries. */
> +static int __init xbc_cmdline_select_cb(char *param, char *val,
> +					const char *unused, void *arg)
>  {
> -	if (!strcmp(param, "bootconfig"))
> -		*(bool *)arg = true;
> +	struct xbc_cmdline_select_ctx *ctx = arg;
> +
> +	if (strcmp(param, "bootconfig"))
> +		return 0;
> +
> +	if (!val) {
> +		ctx->active = true;
> +	} else if (*val == '\0') {
> +		ctx->active = false;
> +	} else if (*val == '+') {
> +		if (!ctx->seen || val[1] != '\0')
> +			ctx->active = true;
> +	} else {
> +		ctx->active = true;
> +	}
> +
> +	if (ctx->cfgs)
> +		__xbc_enable_configs(ctx->cfgs, ctx->count, val,
> +				     &ctx->seen, ctx->warn);
> +	else
> +		ctx->seen = true;
> +
>  	return 0;
>  }
[ ... ]
> +bool __init bootconfig_cmdline_requested(const char *boot_cmdline, int *end_offset)
> +{
> +	struct xbc_config emb = { .name = "", .name_len = 0, .enabled = false };
> +	const char *data;
> +	size_t size;
> +	bool active;
> +
> +	data = xbc_get_embedded_bootconfig(&size);
> +	if (data && xbc_parse_id_header(data, size, &emb) < 0) {
> +		emb.name = "";
> +		emb.name_len = 0;
> +	}
> +
> +	active = xbc_parse_cmdline_bootconfig(boot_cmdline, &emb, 1,
> +					      end_offset, false);
> +	if (IS_ENABLED(CONFIG_BOOT_CONFIG_FORCE) && !active)
> +		return true;
> +
> +	return active && emb.enabled;
> +}

[Severity: Medium]
Does an unmatched bootconfig=<sel> parameter bypass
CONFIG_BOOT_CONFIG_FORCE=y instead of falling back to index 0?

xbc_cmdline_select_cb() sets ctx->active = true for any non-empty val even
when __xbc_enable_configs() finds no matching entry and leaves every
cfgs[i].enabled set to false.  Because active (and bootconfig_found in
setup_boot_config()) is true while no config is enabled, the
CONFIG_BOOT_CONFIG_FORCE fallback (!active / !bootconfig_found) is skipped
in both bootconfig_cmdline_requested() and setup_boot_config(), so no
bootconfig is applied at all.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261127144614.61194-1-mhiramat@kernel.org?part=2

  reply	other threads:[~2026-11-27 15:11 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27 14:46 [RFC PATCH 0/5] bootconfig: Support multiple named bootconfigs in initrd Masami Hiramatsu (Google)
2026-11-27 14:46 ` [RFC PATCH 1/5] bootconfig: Add multi-config ID helpers and xbc_init_configs() support Masami Hiramatsu (Google)
2026-11-27 15:02   ` sashiko-bot
2026-11-27 14:46 ` [RFC PATCH 2/5] bootconfig: Support stacked initrd bootconfigs and bootconfig= selection Masami Hiramatsu (Google)
2026-11-27 15:11   ` sashiko-bot [this message]
2026-11-27 14:46 ` [RFC PATCH 3/5] tools/bootconfig: Support multiple named bootconfigs with -i option Masami Hiramatsu (Google)
2026-11-27 14:46 ` [RFC PATCH 4/5] selftests/ftrace: Add boottime tests for multiple bootconfig selection Masami Hiramatsu (Google)
2026-11-27 14:46 ` [RFC PATCH 5/5] Documentation: bootconfig: Document multiple bootconfigs and selection Masami Hiramatsu (Google)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-237682@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox