From: "Daniel P. Smith" <dpsmith@apertussolutions.com>
To: xen-devel@lists.xenproject.org, Wei Liu <wl@xen.org>
Cc: "Daniel P. Smith" <dpsmith@apertussolutions.com>,
scott.davis@starlab.io, christopher.clark@starlab.io,
"Jan Beulich" <jbeulich@suse.com>,
"Andrew Cooper" <andrew.cooper3@citrix.com>,
"Roger Pau Monné" <roger.pau@citrix.com>,
"George Dunlap" <george.dunlap@citrix.com>,
"Julien Grall" <julien@xen.org>,
"Stefano Stabellini" <sstabellini@kernel.org>
Subject: [PATCH v1 05/18] x86: refactor xen cmdline into general framework
Date: Wed, 6 Jul 2022 17:04:40 -0400 [thread overview]
Message-ID: <20220706210454.30096-6-dpsmith@apertussolutions.com> (raw)
In-Reply-To: <20220706210454.30096-1-dpsmith@apertussolutions.com>
This refactors xen cmdline processing into a general framework
under the new boot info abstraction.
Signed-off-by: Daniel P. Smith <dpsmith@apertussolutions.com>
Reviewed-by: Christopher Clark <christopher.clark@starlab.io>
---
xen/arch/x86/include/asm/bootinfo.h | 49 ++++++++++++++++++++++++
xen/arch/x86/setup.c | 58 ++++-------------------------
xen/include/xen/bootinfo.h | 11 ++++++
3 files changed, 68 insertions(+), 50 deletions(-)
diff --git a/xen/arch/x86/include/asm/bootinfo.h b/xen/arch/x86/include/asm/bootinfo.h
index e5135e402b..2fcd576023 100644
--- a/xen/arch/x86/include/asm/bootinfo.h
+++ b/xen/arch/x86/include/asm/bootinfo.h
@@ -45,4 +45,53 @@ struct __packed mb_memmap {
uint32_t type;
};
+static inline bool loader_is_grub2(const char *loader_name)
+{
+ /* GRUB1="GNU GRUB 0.xx"; GRUB2="GRUB 1.xx" */
+ const char *p = strstr(loader_name, "GRUB ");
+ return (p != NULL) && (p[5] != '0');
+}
+
+static inline char *arch_prepare_cmdline(char *p, struct arch_boot_info *arch)
+{
+ p = p ? : "";
+
+ /* Strip leading whitespace. */
+ while ( *p == ' ' )
+ p++;
+
+ /* GRUB2 and PVH don't not include image name as first item on command line. */
+ if ( !(arch->xenguest || loader_is_grub2(arch->boot_loader_name)) )
+ {
+ /* Strip image name plus whitespace. */
+ while ( (*p != ' ') && (*p != '\0') )
+ p++;
+ while ( *p == ' ' )
+ p++;
+ }
+
+ return p;
+}
+
+static inline char *arch_bootinfo_prepare_cmdline(
+ char *cmdline, struct arch_boot_info *arch)
+{
+ if ( !cmdline )
+ return "";
+
+ if ( (arch->kextra = strstr(cmdline, " -- ")) != NULL )
+ {
+ /*
+ * Options after ' -- ' separator belong to dom0.
+ * 1. Orphan dom0's options from Xen's command line.
+ * 2. Skip all but final leading space from dom0's options.
+ */
+ *arch->kextra = '\0';
+ arch->kextra += 3;
+ while ( arch->kextra[1] == ' ' ) arch->kextra++;
+ }
+
+
+ return arch_prepare_cmdline(cmdline, arch);
+}
#endif
diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c
index ad37f4a658..e4060d6219 100644
--- a/xen/arch/x86/setup.c
+++ b/xen/arch/x86/setup.c
@@ -716,34 +716,6 @@ ignore_param("edid");
*/
ignore_param("placeholder");
-static bool __init loader_is_grub2(const char *loader_name)
-{
- /* GRUB1="GNU GRUB 0.xx"; GRUB2="GRUB 1.xx" */
- const char *p = strstr(loader_name, "GRUB ");
- return (p != NULL) && (p[5] != '0');
-}
-
-static char * __init cmdline_cook(char *p, const char *loader_name)
-{
- p = p ? : "";
-
- /* Strip leading whitespace. */
- while ( *p == ' ' )
- p++;
-
- /* GRUB2 and PVH don't not include image name as first item on command line. */
- if ( xen_guest || loader_is_grub2(loader_name) )
- return p;
-
- /* Strip image name plus whitespace. */
- while ( (*p != ' ') && (*p != '\0') )
- p++;
- while ( *p == ' ' )
- p++;
-
- return p;
-}
-
static unsigned int __init copy_bios_e820(struct e820entry *map, unsigned int limit)
{
unsigned int n = min(bootsym(bios_e820nr), limit);
@@ -754,8 +726,7 @@ static unsigned int __init copy_bios_e820(struct e820entry *map, unsigned int li
return n;
}
-static struct domain *__init create_dom0(
- const struct boot_info *bi, const char *kextra, const char *loader)
+static struct domain *__init create_dom0(const struct boot_info *bi)
{
struct xen_domctl_createdomain dom0_cfg = {
.flags = IS_ENABLED(CONFIG_TBOOT) ? XEN_DOMCTL_CDF_s3_integrity : 0,
@@ -804,16 +775,16 @@ static struct domain *__init create_dom0(
/* Grab the DOM0 command line. */
cmdline = (image->string.kind == BOOTSTR_CMDLINE) ?
image->string.bytes : NULL;
- if ( cmdline || kextra )
+ if ( cmdline || bi->arch->kextra )
{
static char __initdata dom0_cmdline[MAX_GUEST_CMDLINE];
- cmdline = cmdline_cook(cmdline, loader);
+ cmdline = arch_prepare_cmdline(cmdline, bi->arch);
safe_strcpy(dom0_cmdline, cmdline);
- if ( kextra )
+ if ( bi->arch->kextra )
/* kextra always includes exactly one leading space. */
- safe_strcat(dom0_cmdline, kextra);
+ safe_strcat(dom0_cmdline, bi->arch->kextra);
/* Append any extra parameters. */
if ( skip_ioapic_setup && !strstr(dom0_cmdline, "noapic") )
@@ -861,7 +832,7 @@ static struct domain *__init create_dom0(
void __init noreturn __start_xen(unsigned long bi_p)
{
char *memmap_type = NULL;
- char *cmdline, *kextra, *loader;
+ char *cmdline, *loader;
void *bsp_stack;
struct cpu_info *info = get_cpu_info(), *bsp_info;
unsigned int initrdidx, num_parked = 0;
@@ -929,20 +900,7 @@ void __init noreturn __start_xen(unsigned long bi_p)
? boot_info->arch->boot_loader_name : "unknown";
/* Parse the command-line options. */
- cmdline = cmdline_cook((boot_info->arch->flags & BOOTINFO_FLAG_X86_CMDLINE) ?
- boot_info->cmdline : NULL,
- loader);
- if ( (kextra = strstr(cmdline, " -- ")) != NULL )
- {
- /*
- * Options after ' -- ' separator belong to dom0.
- * 1. Orphan dom0's options from Xen's command line.
- * 2. Skip all but final leading space from dom0's options.
- */
- *kextra = '\0';
- kextra += 3;
- while ( kextra[1] == ' ' ) kextra++;
- }
+ cmdline = bootinfo_prepare_cmdline(boot_info);
cmdline_parse(cmdline);
/* Must be after command line argument parsing and before
@@ -1951,7 +1909,7 @@ void __init noreturn __start_xen(unsigned long bi_p)
* We're going to setup domain0 using the module(s) that we stashed safely
* above our heap. The second module, if present, is an initrd ramdisk.
*/
- dom0 = create_dom0(boot_info, kextra, loader);
+ dom0 = create_dom0(boot_info);
if ( !dom0 )
panic("Could not set up DOM0 guest OS\n");
diff --git a/xen/include/xen/bootinfo.h b/xen/include/xen/bootinfo.h
index dde8202f62..477294dc10 100644
--- a/xen/include/xen/bootinfo.h
+++ b/xen/include/xen/bootinfo.h
@@ -53,6 +53,17 @@ struct __packed boot_info {
extern struct boot_info *boot_info;
+static inline char *bootinfo_prepare_cmdline(struct boot_info *bi)
+{
+ bi->cmdline = arch_bootinfo_prepare_cmdline(bi->cmdline, bi->arch);
+
+ if ( *bi->cmdline == ' ' )
+ printk(XENLOG_WARNING "%s: leading whitespace left on cmdline\n",
+ __func__);
+
+ return bi->cmdline;
+}
+
static inline unsigned long bootmodule_next_idx_by_kind(
const struct boot_info *bi, bootmodule_kind kind, unsigned long start)
{
--
2.20.1
next prev parent reply other threads:[~2022-07-06 21:08 UTC|newest]
Thread overview: 66+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-06 21:04 [PATCH v1 00/18] Hyperlaunch Daniel P. Smith
2022-07-06 21:04 ` [PATCH v1 01/18] kconfig: allow configuration of maximum modules Daniel P. Smith
2022-07-07 1:44 ` Henry Wang
2022-07-15 19:16 ` Julien Grall
2022-07-19 16:36 ` Daniel P. Smith
2022-07-26 18:07 ` Julien Grall
2022-07-27 6:12 ` Jan Beulich
2022-07-19 9:32 ` Jan Beulich
2022-07-19 17:02 ` Daniel P. Smith
2022-07-20 7:27 ` Jan Beulich
2022-07-22 15:00 ` Daniel P. Smith
2022-07-06 21:04 ` [PATCH v1 02/18] introduction of generalized boot info Daniel P. Smith
2022-07-15 19:25 ` Julien Grall
2022-07-20 18:32 ` Daniel P. Smith
2022-07-19 13:11 ` Jan Beulich
2022-07-21 14:28 ` Daniel P. Smith
2022-07-21 16:00 ` Jan Beulich
2022-07-21 16:00 ` Jan Beulich
2022-07-22 16:01 ` Daniel P. Smith
2022-07-25 7:05 ` Jan Beulich
2022-07-06 21:04 ` [PATCH v1 03/18] x86: adopt new boot info structures Daniel P. Smith
2022-07-19 13:19 ` Jan Beulich
2022-07-22 12:34 ` Daniel P. Smith
2022-07-06 21:04 ` [PATCH v1 04/18] x86: refactor entrypoints to new boot info Daniel P. Smith
2022-07-18 13:58 ` Smith, Jackson
2022-07-22 12:59 ` Daniel P. Smith
2022-07-06 21:04 ` Daniel P. Smith [this message]
2022-07-19 13:26 ` [PATCH v1 05/18] x86: refactor xen cmdline into general framework Jan Beulich
2022-07-22 13:12 ` Daniel P. Smith
2022-07-25 7:09 ` Jan Beulich
2022-07-06 21:04 ` [PATCH v1 06/18] fdt: make fdt handling reusable across arch Daniel P. Smith
2022-07-07 1:44 ` Henry Wang
2022-07-19 9:36 ` Jan Beulich
2022-07-22 13:18 ` Daniel P. Smith
2022-07-06 21:04 ` [PATCH v1 07/18] docs: update hyperlaunch device tree documentation Daniel P. Smith
2022-07-18 13:57 ` Smith, Jackson
2022-07-22 13:34 ` Daniel P. Smith
2022-07-06 21:04 ` [PATCH v1 08/18] kconfig: introduce domain builder config option Daniel P. Smith
2022-07-07 1:44 ` Henry Wang
2022-07-19 13:29 ` Jan Beulich
2022-07-22 13:47 ` Daniel P. Smith
2022-07-06 21:04 ` [PATCH v1 09/18] x86: introduce abstractions for domain builder Daniel P. Smith
2022-07-26 14:22 ` Jan Beulich
2022-07-06 21:04 ` [PATCH v1 10/18] x86: introduce the " Daniel P. Smith
2022-07-18 13:59 ` Smith, Jackson
2022-07-22 14:36 ` Daniel P. Smith
2022-07-22 20:33 ` Smith, Jackson
2022-07-23 10:45 ` Daniel P. Smith
2022-07-26 14:46 ` Jan Beulich
2022-07-06 21:04 ` [PATCH v1 11/18] x86: initial conversion to " Daniel P. Smith
2022-07-26 15:01 ` Jan Beulich
2022-07-06 21:04 ` [PATCH v1 12/18] x86: convert dom0 creation " Daniel P. Smith
2022-07-27 12:25 ` Jan Beulich
2022-07-06 21:04 ` [PATCH v1 13/18] x86: generalize physmap logic Daniel P. Smith
2022-07-27 12:33 ` Jan Beulich
2022-07-06 21:04 ` [PATCH v1 14/18] x86: generalize vcpu for domain building Daniel P. Smith
2022-07-27 12:46 ` Jan Beulich
2022-07-06 21:04 ` [PATCH v1 15/18] x86: rework domain page allocation Daniel P. Smith
2022-07-27 13:22 ` Jan Beulich
2022-07-06 21:04 ` [PATCH v1 16/18] x86: add pv multidomain construction Daniel P. Smith
2022-07-27 14:12 ` Jan Beulich
2022-07-06 21:04 ` [PATCH v1 17/18] builder: introduce domain builder hypfs tree Daniel P. Smith
2022-07-27 14:30 ` Jan Beulich
2022-07-06 21:04 ` [PATCH v1 18/18] tools: introduce example late pv helper Daniel P. Smith
2022-07-19 17:06 ` [PATCH v1 00/18] Hyperlaunch Smith, Jackson
2022-07-22 14:51 ` Daniel P. Smith
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=20220706210454.30096-6-dpsmith@apertussolutions.com \
--to=dpsmith@apertussolutions.com \
--cc=andrew.cooper3@citrix.com \
--cc=christopher.clark@starlab.io \
--cc=george.dunlap@citrix.com \
--cc=jbeulich@suse.com \
--cc=julien@xen.org \
--cc=roger.pau@citrix.com \
--cc=scott.davis@starlab.io \
--cc=sstabellini@kernel.org \
--cc=wl@xen.org \
--cc=xen-devel@lists.xenproject.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.