From: Borislav Petkov <bp@alien8.de>
To: Evgeniy Baskov <baskov@ispras.ru>
Cc: Dave Hansen <dave.hansen@linux.intel.com>,
Ingo Molnar <mingo@redhat.com>,
Thomas Gleixner <tglx@linutronix.de>,
linux-kernel@vger.kernel.org, x86@kernel.org,
Alexey Khoroshilov <khoroshilov@ispras.ru>
Subject: [PATCH 1/2] x86/boot: Add a function for kernel command line preparation
Date: Tue, 15 Nov 2022 19:59:23 +0100 [thread overview]
Message-ID: <Y3Phi9mO2KSA0AkM@zn.tnic> (raw)
In-Reply-To: <Y3PhYRx9aAYsdvMQ@zn.tnic>
From: Borislav Petkov <bp@suse.de>
Date: Mon, 14 Nov 2022 15:31:59 +0100
Since both the compressed kernel and kernel proper need to deal with the
command line, add a common helper which abstracts away all the details.
Signed-off-by: Borislav Petkov <bp@suse.de>
---
arch/x86/include/asm/shared/cmdline.h | 34 +++++++++++++++++++++++++++
arch/x86/kernel/setup.c | 21 +++--------------
2 files changed, 37 insertions(+), 18 deletions(-)
create mode 100644 arch/x86/include/asm/shared/cmdline.h
diff --git a/arch/x86/include/asm/shared/cmdline.h b/arch/x86/include/asm/shared/cmdline.h
new file mode 100644
index 000000000000..e09c06338567
--- /dev/null
+++ b/arch/x86/include/asm/shared/cmdline.h
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _ASM_X86_SHARED_CMDLINE_H
+#define _ASM_X86_SHARED_CMDLINE_H
+
+#ifdef CONFIG_CMDLINE_BOOL
+#define BUILTIN_CMDLINE CONFIG_CMDLINE
+#else
+#define BUILTIN_CMDLINE ""
+#endif
+
+static inline void cmdline_prepare(char *dst,
+ const char *builtin_cmdline,
+ char *boot_command_line)
+{
+ /* Depends on CONFIG_CMDLINE_BOOL, overwrite with builtin cmdline */
+ if (IS_ENABLED(CONFIG_CMDLINE_OVERRIDE))
+ strscpy(dst, builtin_cmdline, COMMAND_LINE_SIZE);
+ else if (IS_ENABLED(CONFIG_CMDLINE_BOOL)) {
+ if (builtin_cmdline[0]) {
+ /* Add builtin cmdline */
+ strlcat(dst, builtin_cmdline, COMMAND_LINE_SIZE);
+ strlcat(dst, " ", COMMAND_LINE_SIZE);
+ /* Add boot cmdline */
+ strlcat(dst, boot_command_line, COMMAND_LINE_SIZE);
+ }
+ } else {
+ strscpy(dst, boot_command_line, COMMAND_LINE_SIZE);
+ }
+
+ /* Copy back into boot command line, see setup_command_line() */
+ strscpy(boot_command_line, dst, COMMAND_LINE_SIZE);
+}
+
+#endif /* _ASM_X86_SHARED_CMDLINE_H */
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index aacaa96f0195..c506807142a7 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -25,6 +25,7 @@
#include <linux/static_call.h>
#include <linux/swiotlb.h>
#include <linux/random.h>
+#include <linux/vmalloc.h>
#include <uapi/linux/mount.h>
@@ -50,10 +51,10 @@
#include <asm/pci-direct.h>
#include <asm/prom.h>
#include <asm/proto.h>
+#include <asm/shared/cmdline.h>
#include <asm/thermal.h>
#include <asm/unwind.h>
#include <asm/vsyscall.h>
-#include <linux/vmalloc.h>
/*
* max_low_pfn_mapped: highest directly mapped pfn < 4 GB
@@ -168,9 +169,6 @@ unsigned long saved_video_mode;
#define RAMDISK_LOAD_FLAG 0x4000
static char __initdata command_line[COMMAND_LINE_SIZE];
-#ifdef CONFIG_CMDLINE_BOOL
-static char __initdata builtin_cmdline[COMMAND_LINE_SIZE] = CONFIG_CMDLINE;
-#endif
#if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
struct edd edd;
@@ -970,20 +968,7 @@ void __init setup_arch(char **cmdline_p)
bss_resource.start = __pa_symbol(__bss_start);
bss_resource.end = __pa_symbol(__bss_stop)-1;
-#ifdef CONFIG_CMDLINE_BOOL
-#ifdef CONFIG_CMDLINE_OVERRIDE
- 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);
- }
-#endif
-#endif
-
- strscpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
+ cmdline_prepare(command_line, BUILTIN_CMDLINE, boot_command_line);
*cmdline_p = command_line;
/*
--
2.35.1
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette
next prev parent reply other threads:[~2022-11-15 18:59 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-10 13:09 [PATCH v8 0/5] Parse CONFIG_CMDLINE in compressed kernel Evgeniy Baskov
2022-11-10 13:09 ` [PATCH v8 1/5] x86/boot: Add strlcat() and strscpy() to " Evgeniy Baskov
2022-11-10 13:09 ` [PATCH v8 2/5] x86: Add cmdline_prepare() helper Evgeniy Baskov
2022-11-14 14:28 ` Borislav Petkov
2022-11-15 18:58 ` Borislav Petkov
2022-11-15 18:59 ` Borislav Petkov [this message]
2022-11-15 19:00 ` [PATCH 2/2] x86/boot: Use cmdline_prepare() in the compressed stage Borislav Petkov
2022-11-16 10:48 ` Evgeniy Baskov
2022-11-10 13:09 ` [PATCH v8 3/5] x86/setup: Use cmdline_prepare() in setup.c Evgeniy Baskov
2022-11-10 13:09 ` [PATCH v8 4/5] x86/boot: Use cmdline_prapare() in compressed kernel Evgeniy Baskov
2022-11-10 13:09 ` [PATCH v8 5/5] x86/boot: Remove no longer needed includes Evgeniy Baskov
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=Y3Phi9mO2KSA0AkM@zn.tnic \
--to=bp@alien8.de \
--cc=baskov@ispras.ru \
--cc=dave.hansen@linux.intel.com \
--cc=khoroshilov@ispras.ru \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
--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