[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [xen master] x86/setup: lift dom0 creation out into create_dom0() function
commit f546619ce1c5d4de694597c28358cd8e23eea231 Author: David Woodhouse <dwmw@xxxxxxxxxxxx> AuthorDate: Wed May 20 12:47:48 2020 +0200 Commit: Jan Beulich <jbeulich@xxxxxxxx> CommitDate: Wed May 20 12:47:48 2020 +0200 x86/setup: lift dom0 creation out into create_dom0() function The creation of dom0 can be relatively self-contained. Shift it into a separate function and simplify __start_xen() a little bit. This is a cleanup in its own right, but will be even more desireable when live update provides an alternative path through __start_xen() that doesn't involve creating a new dom0 at all. Move the calculation of the 'initrd' parameter for create_dom0() down past the cosmetic printk about NX support, because in the fullness of time the whole initrd and create_dom0() part will be under the same "not live update" conditional. And in the meantime it's just neater. Also drop the explicit check for initrd to be module #0 since that would be the dom0 kernel and the corresponding bit is always clear in module_map. Signed-off-by: David Woodhouse <dwmw@xxxxxxxxxxxx> Acked-by: Jan Beulich <jbeulich@xxxxxxxx> --- xen/arch/x86/setup.c | 173 ++++++++++++++++++++++++++++----------------------- 1 file changed, 94 insertions(+), 79 deletions(-) diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 9e9576344c..2dec7a3fc6 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -681,6 +681,92 @@ static unsigned int __init copy_bios_e820(struct e820entry *map, unsigned int li return n; } +static struct domain *__init create_dom0(const module_t *image, + unsigned long headroom, + module_t *initrd, const char *kextra, + const char *loader) +{ + struct xen_domctl_createdomain dom0_cfg = { + .flags = IS_ENABLED(CONFIG_TBOOT) ? XEN_DOMCTL_CDF_s3_integrity : 0, + .max_evtchn_port = -1, + .max_grant_frames = -1, + .max_maptrack_frames = -1, + .max_vcpus = dom0_max_vcpus(), + }; + struct domain *d; + char *cmdline; + + if ( opt_dom0_pvh ) + { + dom0_cfg.flags |= (XEN_DOMCTL_CDF_hvm | + ((hvm_hap_supported() && !opt_dom0_shadow) ? + XEN_DOMCTL_CDF_hap : 0)); + + dom0_cfg.arch.emulation_flags |= + XEN_X86_EMU_LAPIC | XEN_X86_EMU_IOAPIC | XEN_X86_EMU_VPCI; + } + + if ( iommu_enabled ) + dom0_cfg.flags |= XEN_DOMCTL_CDF_iommu; + + /* Create initial domain 0. */ + d = domain_create(get_initial_domain_id(), &dom0_cfg, !pv_shim); + if ( IS_ERR(d) || (alloc_dom0_vcpu0(d) == NULL) ) + panic("Error creating domain 0\n"); + + /* Grab the DOM0 command line. */ + cmdline = image->string ? __va(image->string) : NULL; + if ( cmdline || kextra ) + { + static char __initdata dom0_cmdline[MAX_GUEST_CMDLINE]; + + cmdline = cmdline_cook(cmdline, loader); + safe_strcpy(dom0_cmdline, cmdline); + + if ( kextra ) + /* kextra always includes exactly one leading space. */ + safe_strcat(dom0_cmdline, kextra); + + /* Append any extra parameters. */ + if ( skip_ioapic_setup && !strstr(dom0_cmdline, "noapic") ) + safe_strcat(dom0_cmdline, " noapic"); + if ( (strlen(acpi_param) == 0) && acpi_disabled ) + { + printk("ACPI is disabled, notifying Domain 0 (acpi=off)\n"); + safe_strcpy(acpi_param, "off"); + } + if ( (strlen(acpi_param) != 0) && !strstr(dom0_cmdline, "acpi=") ) + { + safe_strcat(dom0_cmdline, " acpi="); + safe_strcat(dom0_cmdline, acpi_param); + } + + cmdline = dom0_cmdline; + } + + /* + * Temporarily clear SMAP in CR4 to allow user-accesses in construct_dom0(). + * This saves a large number of corner cases interactions with + * copy_from_user(). + */ + if ( cpu_has_smap ) + { + cr4_pv32_mask &= ~X86_CR4_SMAP; + write_cr4(read_cr4() & ~X86_CR4_SMAP); + } + + if ( construct_dom0(d, image, headroom, initrd, cmdline) != 0 ) + panic("Could not construct domain 0\n"); + + if ( cpu_has_smap ) + { + write_cr4(read_cr4() | X86_CR4_SMAP); + cr4_pv32_mask |= X86_CR4_SMAP; + } + + return d; +} + /* How much of the directmap is prebuilt at compile time. */ #define PREBUILT_MAP_LIMIT (1 << L2_PAGETABLE_SHIFT) @@ -700,12 +786,6 @@ void __init noreturn __start_xen(unsigned long mbi_p) .parity = 'n', .stop_bits = 1 }; - struct xen_domctl_createdomain dom0_cfg = { - .flags = IS_ENABLED(CONFIG_TBOOT) ? XEN_DOMCTL_CDF_s3_integrity : 0, - .max_evtchn_port = -1, - .max_grant_frames = -1, - .max_maptrack_frames = -1, - }; const char *hypervisor_name; /* Critical region without IDT or TSS. Any fault is deadly! */ @@ -1742,58 +1822,13 @@ void __init noreturn __start_xen(unsigned long mbi_p) init_guest_cpuid(); init_guest_msr_policy(); - if ( opt_dom0_pvh ) - { - dom0_cfg.flags |= (XEN_DOMCTL_CDF_hvm | - ((hvm_hap_supported() && !opt_dom0_shadow) ? - XEN_DOMCTL_CDF_hap : 0)); - - dom0_cfg.arch.emulation_flags |= - XEN_X86_EMU_LAPIC | XEN_X86_EMU_IOAPIC | XEN_X86_EMU_VPCI; - } - dom0_cfg.max_vcpus = dom0_max_vcpus(); - - if ( iommu_enabled ) - dom0_cfg.flags |= XEN_DOMCTL_CDF_iommu; - - /* Create initial domain 0. */ - dom0 = domain_create(get_initial_domain_id(), &dom0_cfg, !pv_shim); - if ( IS_ERR(dom0) || (alloc_dom0_vcpu0(dom0) == NULL) ) - panic("Error creating domain 0\n"); - - /* Grab the DOM0 command line. */ - cmdline = (char *)(mod[0].string ? __va(mod[0].string) : NULL); - if ( (cmdline != NULL) || (kextra != NULL) ) - { - static char __initdata dom0_cmdline[MAX_GUEST_CMDLINE]; - - cmdline = cmdline_cook(cmdline, loader); - safe_strcpy(dom0_cmdline, cmdline); - - if ( kextra != NULL ) - /* kextra always includes exactly one leading space. */ - safe_strcat(dom0_cmdline, kextra); - - /* Append any extra parameters. */ - if ( skip_ioapic_setup && !strstr(dom0_cmdline, "noapic") ) - safe_strcat(dom0_cmdline, " noapic"); - if ( (strlen(acpi_param) == 0) && acpi_disabled ) - { - printk("ACPI is disabled, notifying Domain 0 (acpi=off)\n"); - safe_strcpy(acpi_param, "off"); - } - if ( (strlen(acpi_param) != 0) && !strstr(dom0_cmdline, "acpi=") ) - { - safe_strcat(dom0_cmdline, " acpi="); - safe_strcat(dom0_cmdline, acpi_param); - } - - cmdline = dom0_cmdline; - } - if ( xen_cpuidle ) xen_processor_pmbits |= XEN_PROCESSOR_PM_CX; + printk("%sNX (Execute Disable) protection %sactive\n", + cpu_has_nx ? XENLOG_INFO : XENLOG_WARNING "Warning: ", + cpu_has_nx ? "" : "not "); + initrdidx = find_first_bit(module_map, mbi->mods_count); if ( bitmap_weight(module_map, mbi->mods_count) > 1 ) printk(XENLOG_WARNING @@ -1801,35 +1836,15 @@ void __init noreturn __start_xen(unsigned long mbi_p) initrdidx); /* - * Temporarily clear SMAP in CR4 to allow user-accesses in construct_dom0(). - * This saves a large number of corner cases interactions with - * copy_from_user(). - */ - if ( cpu_has_smap ) - { - cr4_pv32_mask &= ~X86_CR4_SMAP; - write_cr4(read_cr4() & ~X86_CR4_SMAP); - } - - printk("%sNX (Execute Disable) protection %sactive\n", - cpu_has_nx ? XENLOG_INFO : XENLOG_WARNING "Warning: ", - cpu_has_nx ? "" : "not "); - - /* * 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. */ - if ( construct_dom0(dom0, mod, modules_headroom, - (initrdidx > 0) && (initrdidx < mbi->mods_count) - ? mod + initrdidx : NULL, cmdline) != 0) + dom0 = create_dom0(mod, modules_headroom, + initrdidx < mbi->mods_count ? mod + initrdidx : NULL, + kextra, loader); + if ( !dom0 ) panic("Could not set up DOM0 guest OS\n"); - if ( cpu_has_smap ) - { - write_cr4(read_cr4() | X86_CR4_SMAP); - cr4_pv32_mask |= X86_CR4_SMAP; - } - heap_init_late(); init_trace_bufs(); -- generated by git-patchbot for /home/xen/git/xen.git#master
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |