mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Borislav Petkov <bp@alien8.de>
To: x86-ml <x86@kernel.org>
Cc: linux-tip-commits@vger.kernel.org,
	Julian Stecklina <julian.stecklina@cyberus-technology.de>,
	Ingo Molnar <mingo@kernel.org>, Kees Cook <keescook@chromium.org>,
	linux-kernel@vger.kernel.org, x86@kernel.org
Subject: Re: [tip: x86/boot] x86/boot: Move kernel cmdline setup earlier in the boot process (again)
Date: Mon, 8 Apr 2024 20:17:32 +0200	[thread overview]
Message-ID: <20240408181732.GCZhQ0vGSfP3Gf8tDW@fat_crate.local> (raw)
In-Reply-To: <171169867308.10875.15117897441999380027.tip-bot2@tip-bot2>

On Fri, Mar 29, 2024 at 07:51:13AM -0000, tip-bot2 for Julian Stecklina wrote:
> The following commit has been merged into the x86/boot branch of tip:
> 
> Commit-ID:     4faa0e5d6d79fc4c6e1943e8b62a65744d8439a0
> Gitweb:        https://git.kernel.org/tip/4faa0e5d6d79fc4c6e1943e8b62a65744d8439a0
> Author:        Julian Stecklina <julian.stecklina@cyberus-technology.de>
> AuthorDate:    Thu, 28 Mar 2024 16:42:12 +01:00
> Committer:     Ingo Molnar <mingo@kernel.org>
> CommitterDate: Fri, 29 Mar 2024 08:19:12 +01:00
> 
> x86/boot: Move kernel cmdline setup earlier in the boot process (again)

...

> The order is now:
> 
> 	setup_arch():
> 	  -> Assemble final command line:
> 	     boot_command_line = builtin_cmdline + boot_cmdline
> 
> 	  -> early_cpu_init()
> 	    -> early_identify_cpu()
> 	      -> sld_setup()
> 		-> sld_state_setup()
> 		  -> Looks for split_lock_detect in boot_command_line
> 
> 	  -> e820__memory_setup()
> 
> 	  -> parse_early_param()

So that thing. Should we do something like the silly thing below so that
it catches potential issues with parsing builtin cmdline stuff too
early?

diff --git a/arch/x86/include/asm/setup.h b/arch/x86/include/asm/setup.h
index e61e68d71cba..2e1d19e103e6 100644
--- a/arch/x86/include/asm/setup.h
+++ b/arch/x86/include/asm/setup.h
@@ -7,6 +7,7 @@
 #define COMMAND_LINE_SIZE 2048
 
 #include <linux/linkage.h>
+
 #include <asm/page_types.h>
 #include <asm/ibt.h>
 
@@ -28,6 +29,8 @@
 #define NEW_CL_POINTER		0x228	/* Relative to real mode data */
 
 #ifndef __ASSEMBLY__
+#include <linux/cache.h>
+
 #include <asm/bootparam.h>
 #include <asm/x86_init.h>
 
@@ -133,6 +136,12 @@ asmlinkage void __init __noreturn x86_64_start_reservations(char *real_mode_data
 #endif /* __i386__ */
 #endif /* _SETUP */
 
+#ifdef CONFIG_CMDLINE_BOOL
+extern bool builtin_cmdline_added __ro_after_init;
+#else
+#define builtin_cmdline_added 0
+#endif
+
 #else  /* __ASSEMBLY */
 
 .macro __RESERVE_BRK name, size
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index 55a1fc332e20..a35ca100f57c 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -165,6 +165,7 @@ unsigned long saved_video_mode;
 static char __initdata command_line[COMMAND_LINE_SIZE];
 #ifdef CONFIG_CMDLINE_BOOL
 static char __initdata builtin_cmdline[COMMAND_LINE_SIZE] = CONFIG_CMDLINE;
+bool builtin_cmdline_added __ro_after_init;
 #endif
 
 #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
@@ -765,6 +766,7 @@ void __init setup_arch(char **cmdline_p)
 		strscpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
 	}
 #endif
+	builtin_cmdline_added = true;
 #endif
 
 	strscpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
diff --git a/arch/x86/lib/cmdline.c b/arch/x86/lib/cmdline.c
index 80570eb3c89b..6307cd62acd7 100644
--- a/arch/x86/lib/cmdline.c
+++ b/arch/x86/lib/cmdline.c
@@ -6,9 +6,12 @@
 #include <linux/kernel.h>
 #include <linux/string.h>
 #include <linux/ctype.h>
+
 #include <asm/setup.h>
 #include <asm/cmdline.h>
 
+#include <asm/bug.h>
+
 static inline int myisspace(u8 c)
 {
 	return c <= ' ';	/* Close enough approximation */
@@ -205,12 +208,16 @@ __cmdline_find_option(const char *cmdline, int max_cmdline_size,
 
 int cmdline_find_option_bool(const char *cmdline, const char *option)
 {
+	WARN_ON_ONCE(!builtin_cmdline_added);
+
 	return __cmdline_find_option_bool(cmdline, COMMAND_LINE_SIZE, option);
 }
 
 int cmdline_find_option(const char *cmdline, const char *option, char *buffer,
 			int bufsize)
 {
+	WARN_ON_ONCE(!builtin_cmdline_added);
+
 	return __cmdline_find_option(cmdline, COMMAND_LINE_SIZE, option,
 				     buffer, bufsize);
 }

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette

  reply	other threads:[~2024-04-08 18:17 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-29  7:51 tip-bot2 for Julian Stecklina
2024-04-08 18:17 ` Borislav Petkov [this message]
2024-04-08 18:27   ` Ingo Molnar
2024-04-09 15:25     ` [PATCH] x86/setup: Warn when option parsing is done too early Borislav Petkov
2024-05-27 17:32       ` [tip: x86/boot] " tip-bot2 for Borislav Petkov (AMD)

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=20240408181732.GCZhQ0vGSfP3Gf8tDW@fat_crate.local \
    --to=bp@alien8.de \
    --cc=julian.stecklina@cyberus-technology.de \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=x86@kernel.org \
    /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

all inboxes | Powered by JetHome®