lkml.org 
[lkml]   [2022]   [Nov]   [15]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[PATCH 1/2] x86/boot: Add a function for kernel command line preparation
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

\
 
 \ /
  Last update: 2022-11-15 19:59    [W:0.064 / U:0.088 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site