* [PATCH RESEND] x86/boot: Add option to append to the cmdline
@ 2025-09-15 20:26 Brian Mak
0 siblings, 0 replies; 5+ messages in thread
From: Brian Mak @ 2025-09-15 20:26 UTC (permalink / raw)
To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
H. Peter Anvin, x86, linux-kernel
Cc: Brian Mak
Currently, the bootloader-provided command line can be prepended to with
the built-in command line. This is done by enabling CONFIG_CMDLINE_BOOL
and specifying a CONFIG_CMDLINE value with CONFIG_CMDLINE_OVERRIDE
disabled.
However, there is currently no way to append the built-in command line
to the bootloader-provided command line, like there is on some other
architectures. This is necessary to work around bootloaders that are
difficult to update, where we want to override a subset of the
bootloader-provided values and keep the others.
To solve this limitation, we add CONFIG_CMDLINE_EXTEND, which is already
available on several other architectures, to make the built-in command
line append to the bootloader-provided command line.
Signed-off-by: Brian Mak <makb@juniper.net>
---
arch/x86/Kconfig | 9 +++++++++
arch/x86/kernel/setup.c | 13 +++++++++----
2 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 58d890fe2100..8da39ebaddf4 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -2275,6 +2275,15 @@ config CMDLINE_BOOL
Systems with fully functional boot loaders (i.e. non-embedded)
should leave this option set to 'N'.
+config CMDLINE_EXTEND
+ bool "Extend bootloader kernel arguments"
+ depends on CMDLINE_BOOL && !CMDLINE_OVERRIDE
+ help
+ The built-in command line will be appended to the command-
+ line arguments provided during boot. This is useful in
+ cases where the provided arguments are insufficient and
+ you don't want to or cannot modify them.
+
config CMDLINE
string "Built-in kernel command string"
depends on CMDLINE_BOOL
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index 1b2edd07a3e1..86e4d8ab8558 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -911,10 +911,15 @@ void __init setup_arch(char **cmdline_p)
strscpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
#else
if (builtin_cmdline[0]) {
- /* append boot loader cmdline to builtin */
- strlcat(builtin_cmdline, " ", COMMAND_LINE_SIZE);
- strlcat(builtin_cmdline, boot_command_line, COMMAND_LINE_SIZE);
- strscpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
+ if (!IS_ENABLED(CONFIG_CMDLINE_EXTEND)) {
+ /* append boot loader cmdline to builtin */
+ strlcat(builtin_cmdline, " ", COMMAND_LINE_SIZE);
+ strlcat(builtin_cmdline, boot_command_line, COMMAND_LINE_SIZE);
+ strscpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
+ } else {
+ strlcat(boot_command_line, " ", COMMAND_LINE_SIZE);
+ strlcat(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
+ }
}
#endif
builtin_cmdline_added = true;
base-commit: 1b237f190eb3d36f52dffe07a40b5eb210280e00
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH RESEND] x86/boot: Add option to append to the cmdline
@ 2025-10-01 23:04 Brian Mak
2025-10-02 0:13 ` Dave Hansen
0 siblings, 1 reply; 5+ messages in thread
From: Brian Mak @ 2025-10-01 23:04 UTC (permalink / raw)
To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
H. Peter Anvin, Andrew Morton, x86, linux-kernel
Cc: Brian Mak
Currently, the bootloader-provided command line can be prepended to with
the built-in command line. This is done by enabling CONFIG_CMDLINE_BOOL
and specifying a CONFIG_CMDLINE value with CONFIG_CMDLINE_OVERRIDE
disabled.
However, there is currently no way to append the built-in command line
to the bootloader-provided command line, like there is on some other
architectures. This is necessary to work around bootloaders that are
difficult to update, where we want to override a subset of the
bootloader-provided values and keep the others.
To solve this limitation, we add CONFIG_CMDLINE_EXTEND, which is already
available on several other architectures, to make the built-in command
line append to the bootloader-provided command line.
Signed-off-by: Brian Mak <makb@juniper.net>
---
Hi all,
I'm not sure if I'm reaching the right audience since I haven't received a
response in the past two times I sent this patch, so I'm adding Andrew
Morton to this patch as well.
Best,
Brian
arch/x86/Kconfig | 9 +++++++++
arch/x86/kernel/setup.c | 13 +++++++++----
2 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 58d890fe2100..8da39ebaddf4 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -2275,6 +2275,15 @@ config CMDLINE_BOOL
Systems with fully functional boot loaders (i.e. non-embedded)
should leave this option set to 'N'.
+config CMDLINE_EXTEND
+ bool "Extend bootloader kernel arguments"
+ depends on CMDLINE_BOOL && !CMDLINE_OVERRIDE
+ help
+ The built-in command line will be appended to the command-
+ line arguments provided during boot. This is useful in
+ cases where the provided arguments are insufficient and
+ you don't want to or cannot modify them.
+
config CMDLINE
string "Built-in kernel command string"
depends on CMDLINE_BOOL
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index 1b2edd07a3e1..86e4d8ab8558 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -911,10 +911,15 @@ void __init setup_arch(char **cmdline_p)
strscpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
#else
if (builtin_cmdline[0]) {
- /* append boot loader cmdline to builtin */
- strlcat(builtin_cmdline, " ", COMMAND_LINE_SIZE);
- strlcat(builtin_cmdline, boot_command_line, COMMAND_LINE_SIZE);
- strscpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
+ if (!IS_ENABLED(CONFIG_CMDLINE_EXTEND)) {
+ /* append boot loader cmdline to builtin */
+ strlcat(builtin_cmdline, " ", COMMAND_LINE_SIZE);
+ strlcat(builtin_cmdline, boot_command_line, COMMAND_LINE_SIZE);
+ strscpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
+ } else {
+ strlcat(boot_command_line, " ", COMMAND_LINE_SIZE);
+ strlcat(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
+ }
}
#endif
builtin_cmdline_added = true;
base-commit: 1b237f190eb3d36f52dffe07a40b5eb210280e00
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH RESEND] x86/boot: Add option to append to the cmdline
2025-10-01 23:04 [PATCH RESEND] x86/boot: Add option to append to the cmdline Brian Mak
@ 2025-10-02 0:13 ` Dave Hansen
2025-10-02 17:30 ` Brian Mak
0 siblings, 1 reply; 5+ messages in thread
From: Dave Hansen @ 2025-10-02 0:13 UTC (permalink / raw)
To: Brian Mak, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
Dave Hansen, H. Peter Anvin, Andrew Morton, x86, linux-kernel
On 10/1/25 16:04, Brian Mak wrote:
> To solve this limitation, we add CONFIG_CMDLINE_EXTEND, which is already
> available on several other architectures, to make the built-in command
> line append to the bootloader-provided command line.
I'd really rather not have another copy-and-paste of another
architecture's Kconfig bits into x86.
At the _very_ least, we'd get a boolean ARCH_HAS_CMDLIND_EXTEND which
would then expose an arch-independent CMDLINE_EXTEND option. Literally
duplicating Kconfig options just isn't scalable.
I also cringe every time I see code like this get added to arch/x86 that
really doesn't have anything to do with x86 and really only gets dumped
in to arch/ because there's never been a proper refactoring of all the
copy-and-pasted code.
In the end, refactoring Kconfig is dirt simple. Refactoring
builtin_cmdline[] into arch-independent code would be a lot harder.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH RESEND] x86/boot: Add option to append to the cmdline
2025-10-02 0:13 ` Dave Hansen
@ 2025-10-02 17:30 ` Brian Mak
2025-10-02 20:33 ` Daniel Walker (danielwa)
0 siblings, 1 reply; 5+ messages in thread
From: Brian Mak @ 2025-10-02 17:30 UTC (permalink / raw)
To: Dave Hansen
Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
H. Peter Anvin, Andrew Morton, Daniel Walker, x86@kernel.org,
linux-kernel@vger.kernel.org
On Oct 1, 2025, at 5:13 PM, Dave Hansen <dave.hansen@intel.com> wrote:
> On 10/1/25 16:04, Brian Mak wrote:
>> To solve this limitation, we add CONFIG_CMDLINE_EXTEND, which is already
>> available on several other architectures, to make the built-in command
>> line append to the bootloader-provided command line.
>
> I'd really rather not have another copy-and-paste of another
> architecture's Kconfig bits into x86.
>
> At the _very_ least, we'd get a boolean ARCH_HAS_CMDLIND_EXTEND which
> would then expose an arch-independent CMDLINE_EXTEND option. Literally
> duplicating Kconfig options just isn't scalable.
Hi Dave,
Thanks for your comments!
Sure, I'll introduce an arch-independent (ARCH_HAS_)CMDLINE_EXTEND option
in v2.
> I also cringe every time I see code like this get added to arch/x86 that
> really doesn't have anything to do with x86 and really only gets dumped
> in to arch/ because there's never been a proper refactoring of all the
> copy-and-pasted code.
>
> In the end, refactoring Kconfig is dirt simple. Refactoring
> builtin_cmdline[] into arch-independent code would be a lot harder.
In the past, there have been efforts to add arch-independent cmdline
processing [1] (CC: Daniel Walker). These efforts have been stalled for a
long time now though.
[1] https://lore.kernel.org/lkml/20231110013817.2378507-1-danielwa@cisco.com/
Thanks,
Brian
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH RESEND] x86/boot: Add option to append to the cmdline
2025-10-02 17:30 ` Brian Mak
@ 2025-10-02 20:33 ` Daniel Walker (danielwa)
0 siblings, 0 replies; 5+ messages in thread
From: Daniel Walker (danielwa) @ 2025-10-02 20:33 UTC (permalink / raw)
To: Brian Mak
Cc: Dave Hansen, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
Dave Hansen, H. Peter Anvin, Andrew Morton, x86@kernel.org,
linux-kernel@vger.kernel.org
On Thu, Oct 02, 2025 at 05:30:10PM +0000, Brian Mak wrote:
> On Oct 1, 2025, at 5:13 PM, Dave Hansen <dave.hansen@intel.com> wrote:
>
> > On 10/1/25 16:04, Brian Mak wrote:
> >> To solve this limitation, we add CONFIG_CMDLINE_EXTEND, which is already
> >> available on several other architectures, to make the built-in command
> >> line append to the bootloader-provided command line.
> >
> > I'd really rather not have another copy-and-paste of another
> > architecture's Kconfig bits into x86.
> >
> > At the _very_ least, we'd get a boolean ARCH_HAS_CMDLIND_EXTEND which
> > would then expose an arch-independent CMDLINE_EXTEND option. Literally
> > duplicating Kconfig options just isn't scalable.
>
> Hi Dave,
>
> Thanks for your comments!
>
> Sure, I'll introduce an arch-independent (ARCH_HAS_)CMDLINE_EXTEND option
> in v2.
>
> > I also cringe every time I see code like this get added to arch/x86 that
> > really doesn't have anything to do with x86 and really only gets dumped
> > in to arch/ because there's never been a proper refactoring of all the
> > copy-and-pasted code.
> >
> > In the end, refactoring Kconfig is dirt simple. Refactoring
> > builtin_cmdline[] into arch-independent code would be a lot harder.
>
> In the past, there have been efforts to add arch-independent cmdline
> processing [1] (CC: Daniel Walker). These efforts have been stalled for a
> long time now though.
We use my change at Cisco in production, but I don't submit it often enough.
Daniel
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-10-02 20:35 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-01 23:04 [PATCH RESEND] x86/boot: Add option to append to the cmdline Brian Mak
2025-10-02 0:13 ` Dave Hansen
2025-10-02 17:30 ` Brian Mak
2025-10-02 20:33 ` Daniel Walker (danielwa)
-- strict thread matches above, loose matches on Subject: below --
2025-09-15 20:26 Brian Mak
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox