From: Baoquan He <bhe@redhat.com>
To: Usama Arif <usamaarif642@gmail.com>
Cc: kexec@lists.infradead.org, horms@verge.net.au,
paulmck@kernel.org, leitao@debian.org, kernel-team@meta.com
Subject: Re: [RFC] kexec: Add bootconfig support to get_command_line
Date: Thu, 21 Aug 2025 11:28:04 +0800 [thread overview]
Message-ID: <aKaSRJ9HGNR07Svl@MiWiFi-R3L-srv> (raw)
In-Reply-To: <20250811153736.3865487-1-usamaarif642@gmail.com>
Hi,
On 08/11/25 at 04:37pm, Usama Arif wrote:
> If the kernel is enabled with CONFIG_BOOT_CONFIG_FORCE, it will
> always append the bootconfig at the start of the kernel commandline.
> If reuse-cmdline option is used in kexec, the bootconfig will be
> repeatedly appended at the start of the commandline on every kexec.
> As there is a limit on the size of kernel commandline that can be
> used, --reuse-cmdline option will break kexec depending on the
> size of bootconfig on repeated kexec.
>
> Bootconfig is embedded in the kernel, so it should not be considered
> when reusing kernel command line.
> Modify get_command_line() to first attempt reading kernel parameters
> from /proc/bootconfig before falling back to /proc/cmdline. This allows
> kexec to use the original boot parameters without bootconfig which
> is embedded in the kernel.
Thanks for the great fix. While I have some questions about the change.
1, if we can read kernel parameters from /proc/bootconfig, does it mean
we will skip other kernel parameters, e.g I set some parameters in
grub, meanwhile set bootconfg? Is this allowed?
2. If /proc/bootconfig includes the whole kernel parameters of the
runnign kernel, setup_boot_config() will parse and append bootconfig
to kernel cmdline again, right? But it doesn't matter.
Sorry, I am not familiar with bootconfig.
Thanks
Baoquan
>
> The function will fallback to /proc/cmdline behavior when:
>
> - /proc/bootconfig doesn't exist
> - /proc/bootconfig is empty
> - /proc/bootconfig doesn't contain the expected marker format
> - The extracted parameter line is empty
>
> Signed-off-by: Usama Arif <usamaarif642@gmail.com>
> ---
> kexec/kexec.c | 50 ++++++++++++++++++++++++++++++++++++++++++++------
> 1 file changed, 44 insertions(+), 6 deletions(-)
>
> diff --git a/kexec/kexec.c b/kexec/kexec.c
> index 6bf12d7..b31cb1f 100644
> --- a/kexec/kexec.c
> +++ b/kexec/kexec.c
> @@ -1235,15 +1235,53 @@ static char *slurp_proc_file(const char *filename, size_t *len)
> */
> char *get_command_line(void)
> {
> - char *p, *line;
> + char *p, *line = NULL;
> size_t size;
> + char *bootconfig_line;
> + size_t bootconfig_size;
> +
> + /* First try to get command line parameters from /proc/bootconfig */
> + bootconfig_line = slurp_proc_file("/proc/bootconfig", &bootconfig_size);
> + if (bootconfig_line && bootconfig_size > 0) {
> + /* Look for "# Parameters from bootloader:" */
> + char *params_marker = strstr(bootconfig_line, "# Parameters from bootloader:");
> + if (params_marker) {
> + /* Find the next line after the marker */
> + char *params_start = strchr(params_marker, '\n');
> + if (params_start) {
> + params_start++; /* Move past the newline */
> +
> + /* Check if this line starts with "# " */
> + if (strncmp(params_start, "# ", 2) == 0) {
> + /* Skip the "# " prefix */
> + params_start += 2;
> +
> + /* Find the end of the line */
> + char *params_end = strchr(params_start, '\n');
> + if (params_end) {
> + *params_end = '\0';
> + }
> +
> + /* Check if the extracted line is not empty */
> + if (strlen(params_start) > 0) {
> + /* Allocate and copy the parameters */
> + line = xstrdup(params_start);
> + }
> + }
> + }
> + }
> + free(bootconfig_line);
> + }
>
> - line = slurp_proc_file("/proc/cmdline", &size);
> - if (!line || !size)
> - die("Failed to read /proc/cmdline\n");
> + /* Fall back to reading /proc/cmdline if we didn't get a line from bootconfig */
> + if (!line) {
> + line = slurp_proc_file("/proc/cmdline", &size);
> + if (!line || !size)
> + die("Failed to read /proc/cmdline\n");
>
> - /* strip newline */
> - line[size-1] = '\0';
> + /* strip newline */
> + line[size-1] = '\0';
> + }
>
> p = strpbrk(line, "\r\n");
> if (p)
> --
> 2.47.3
>
>
next prev parent reply other threads:[~2025-08-21 4:49 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-11 15:37 [RFC] kexec: Add bootconfig support to get_command_line Usama Arif
2025-08-11 16:21 ` Paul E. McKenney
2025-08-20 13:01 ` Breno Leitao
2025-08-21 3:28 ` Baoquan He [this message]
2025-08-21 11:32 ` Usama Arif
2025-08-22 3:53 ` Baoquan He
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=aKaSRJ9HGNR07Svl@MiWiFi-R3L-srv \
--to=bhe@redhat.com \
--cc=horms@verge.net.au \
--cc=kernel-team@meta.com \
--cc=kexec@lists.infradead.org \
--cc=leitao@debian.org \
--cc=paulmck@kernel.org \
--cc=usamaarif642@gmail.com \
/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