[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH v3] xen: Allow a default compiled-in command line using Kconfig
Added 3 new config entries in common/Kconfig: CMDLINE_BOOL, CMDLINE and CMDLINE_OVERRIDE These 3 entries enable an embedded command line to be compiled in the hypervisor. If CMDLINE_BOOL is set to y, both arm and x86 startup routines will append the bootloader command line to the built-in one, forming the complete command line. This order of concatenation implies that if any options are set in both the built-in and bootloader command line, only the ones in the latter will take effect. And if CMDLINE_OVERRIDE is set to y, the whole bootloader command line will be ignored, which will be useful to work around broken bootloaders. This allows downstreams to set their defaults without modifying the source code all over the place. Also probably useful for the embedded space. See Also: https://xenproject.atlassian.net/browse/XEN-41 Signed-off-by: Zhongze Liu <blackskygg@xxxxxxxxx> --- Changed since v2: * Clarify the parsing order (and thus the overiding behavior) of the two commandlines when parsing. * Shortened the XEN-41 issue url in the commit message. * Wrap the related work into a #ifdef CONFIG_CMDLINE_BOOL block in various setup.c's. --- xen/arch/arm/setup.c | 30 +++++++++++++++++-- xen/arch/x86/setup.c | 84 ++++++++++++++++++++++++++++++++++++++++++++-------- xen/common/Kconfig | 40 +++++++++++++++++++++++++ 3 files changed, 139 insertions(+), 15 deletions(-) diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index 92a2de6b70..e6b8f4da34 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -705,10 +705,16 @@ void __init start_xen(unsigned long boot_phys_offset, size_t fdt_size; int cpus, i; paddr_t xen_paddr; - const char *cmdline; + const char *cmdline, *boot_cmdline; struct bootmodule *xen_bootmodule; struct domain *dom0; struct xen_arch_domainconfig config; +#ifdef CONFIG_CMDLINE_BOOL + static xen_commandline_t __initdata builtin_cmdline = CONFIG_CMDLINE; +#ifndef CONFIG_CMDLINE_OVERRIDE + static xen_commandline_t __initdata complete_cmdline = ""; +#endif /* CONFIG_CMDLINE_OVERRIDE */ +#endif /* CONFIG_CMDLINE_BOOL */ setup_cache(); @@ -729,7 +735,27 @@ void __init start_xen(unsigned long boot_phys_offset, + (fdt_paddr & ((1 << SECOND_SHIFT) - 1)); fdt_size = boot_fdt_info(device_tree_flattened, fdt_paddr); - cmdline = boot_fdt_cmdline(device_tree_flattened); + boot_cmdline = boot_fdt_cmdline(device_tree_flattened); + cmdline = boot_cmdline; + +#ifdef CONFIG_CMDLINE_BOOL + /* Process the built-in command line options. */ + + printk("Compiled-in command line: %s\n", builtin_cmdline); + +#ifdef CONFIG_CMDLINE_OVERRIDE + /* Ignore the bootloader cmdline. */ + cmdline = builtin_cmdline; +#else + safe_strcat(complete_cmdline, builtin_cmdline); + safe_strcat(complete_cmdline, " "); + safe_strcat(complete_cmdline, boot_cmdline); + + cmdline = complete_cmdline; +#endif /* CONFIG_CMDLINE_OVERRIDE */ + +#endif /* CONFIG_CMDLINE_BOOL */ + printk("Command line: %s\n", cmdline); cmdline_parse(cmdline); diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index dab67d5491..3a6341fd3c 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -636,10 +636,41 @@ static char * __init cmdline_cook(char *p, const char *loader_name) return p; } +/* + * Extracts dom0 options from the commandline. + * + * 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. + */ + +static inline char* __init extract_dom0_options(char *cmdline) +{ + char *kextra; + + if ( (kextra = strstr(cmdline, " -- ")) != NULL ) + { + *kextra = '\0'; + kextra += 3; + while ( kextra[1] == ' ' ) kextra++; + } + + return kextra; +} + void __init noreturn __start_xen(unsigned long mbi_p) { char *memmap_type = NULL; - char *cmdline, *kextra, *loader; + char *boot_cmdline, *boot_kextra, *loader; + char *cmdline, *kextra = NULL; +#ifdef CONFIG_CMDLINE_BOOL + static xen_commandline_t __initdata builtin_cmdline = CONFIG_CMDLINE; + char *builtin_kextra; +#ifndef CONFIG_CMDLINE_OVERRIDE + static xen_commandline_t __initdata complete_cmdline = ""; + static char __initdata complete_kextra[MAX_GUEST_CMDLINE] = ""; +#endif /* CONFIG_CMDLINE_OVERRIDE */ +#endif /* CONFIG_CMDLINE_BOOL */ unsigned int initrdidx, domcr_flags = DOMCRF_s3_integrity; multiboot_info_t *mbi = __va(mbi_p); module_t *mod = (module_t *)__va(mbi->mods_addr); @@ -676,20 +707,47 @@ void __init noreturn __start_xen(unsigned long mbi_p) ? (char *)__va(mbi->boot_loader_name) : "unknown"; /* Parse the command-line options. */ - cmdline = cmdline_cook((mbi->flags & MBI_CMDLINE) ? - __va(mbi->cmdline) : NULL, - loader); - if ( (kextra = strstr(cmdline, " -- ")) != NULL ) + + boot_cmdline = cmdline_cook((mbi->flags & MBI_CMDLINE) ? + __va(mbi->cmdline) : NULL, + loader); + boot_kextra = extract_dom0_options(boot_cmdline); + cmdline = boot_cmdline; + kextra = boot_kextra; + +#ifdef CONFIG_CMDLINE_BOOL + /* Process the built-in command line options. */ + builtin_kextra = extract_dom0_options(builtin_cmdline); + printk("Compiled-in command line: %s\n", builtin_cmdline); + +#ifdef CONFIG_CMDLINE_OVERRIDE + /* Ignore the bootloader cmdline. */ + cmdline = builtin_cmdline; + kextra = builtin_kextra; +#else + /* Append the bootloader cmdline to the builtin one + * to form the complete cmdline. And do the same to dom0 options. */ + safe_strcat(complete_cmdline, builtin_cmdline); + safe_strcat(complete_cmdline, " "); + safe_strcat(complete_cmdline, boot_cmdline); + + if ( builtin_kextra != 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++; + safe_strcat(complete_kextra, builtin_kextra); + safe_strcat(complete_kextra, " "); + } + if ( boot_kextra != NULL ) + { + safe_strcat(complete_kextra, boot_kextra); } + + cmdline = complete_cmdline; + /* kextra should be NULL if it's empty */ + kextra = complete_kextra[0] ? complete_kextra : NULL; +#endif /* CONFIG_CMDLINE_OVERRIDE */ + +#endif /* CONFIG_CMDLINE_BOOL */ + cmdline_parse(cmdline); /* Must be after command line argument parsing and before diff --git a/xen/common/Kconfig b/xen/common/Kconfig index f2ecbc43d6..544b8e7804 100644 --- a/xen/common/Kconfig +++ b/xen/common/Kconfig @@ -237,4 +237,44 @@ config FAST_SYMBOL_LOOKUP The only user of this is Live patching. If unsure, say Y. + +config CMDLINE_BOOL + bool "Built-in hypervisor command line" + default n + ---help--- + Allow for specifying boot arguments to the hypervisor at + build time. On some systems (e.g. embedded ones), it is + necessary or convenient to provide some or all of the + hypervisor boot arguments with the hypervisor itself (that is, + to not rely on the bootloader to provide them.) + + To compile command line arguments into the hypervisor, + set this option to 'Y', then fill in the + boot arguments in CONFIG_CMDLINE. + +config CMDLINE + string "Built-in hypervisor command string" + depends on CMDLINE_BOOL + default "" + ---help--- + Enter arguments here that should be compiled into the hypervisor + image and used at boot time. If the bootloader provides a + command line at boot time, it is appended to this string to + form the full hypervisor command line, when the system boots. + So if the same command line option was set twice, only the latter + (i.e. the one in the bootloader command line), will take effect. + + However, you can use the CONFIG_CMDLINE_OVERRIDE option to + change this behavior. + +config CMDLINE_OVERRIDE + bool "Built-in command line overrides bootloader arguments" + default n + depends on CMDLINE_BOOL + ---help--- + Set this option to 'Y' to have the hypervisor ignore the bootloader + command line, and use ONLY the built-in command line. + + This is used to work around broken bootloaders. This should + be set to 'N' under normal conditions. endmenu -- 2.12.0 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx https://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |