From patchwork Thu Jan 30 16:13:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Woodhouse X-Patchwork-Id: 11358317 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 16149139A for ; Thu, 30 Jan 2020 16:16:23 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DAE7B20707 for ; Thu, 30 Jan 2020 16:16:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="ml6Qa2Bi" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DAE7B20707 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ixCTS-0005K8-6U; Thu, 30 Jan 2020 16:15:22 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ixCTQ-0005Iv-Q3 for xen-devel@lists.xenproject.org; Thu, 30 Jan 2020 16:15:20 +0000 X-Inumbo-ID: 78cae798-437b-11ea-a933-bc764e2007e4 Received: from merlin.infradead.org (unknown [2001:8b0:10b:1231::1]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 78cae798-437b-11ea-a933-bc764e2007e4; Thu, 30 Jan 2020 16:13:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=h+oTXoHnIIrP6hDWy90HME6sh9qFOM8efyxFfaYTYHA=; b=ml6Qa2BimcK1mSml0OacL9n6Ci OHEbZKZxl2PzoHdT/i7lLXwsXFpA7qBIm96O5ZlLJBeOom17RbIHLBThzFTP6ySgnnLrxII7DCHMJ m0Q7uNQVI+NjN0Kh2O73PI5BGDzXheyy53ucPa0rYr00hOxDvT6zL+CqfsaGxSZHMBBSvG9Jrtijd vUX2QFX7ay7KEcw8oK8qLYQ1esmj2fXxxm95o2PTN/azprEaRsdJlhQY78DOqIHwnPxsttEaQTMFm 87u89PjdSuV7THXAkZ2fAdtN22UGjEHjaMaUt9iqwEDPzhnzG++T35K2DYxRazAbV/IC8DLDcpre1 P3HpAyRA==; Received: from i7.infradead.org ([2001:8b0:10b:1:21e:67ff:fecb:7a92]) by merlin.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1ixCRf-0005Tp-Dt; Thu, 30 Jan 2020 16:13:31 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.92 #3 (Red Hat Linux)) id 1ixCRe-009keM-K6; Thu, 30 Jan 2020 16:13:30 +0000 From: David Woodhouse To: Xen-devel Date: Thu, 30 Jan 2020 16:13:28 +0000 Message-Id: <20200130161330.2324143-20-dwmw2@infradead.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200130161330.2324143-1-dwmw2@infradead.org> References: <20200130161330.2324143-1-dwmw2@infradead.org> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by merlin.infradead.org. See http://www.infradead.org/rpr.html Subject: [Xen-devel] [RFC PATCH v3 20/22] x86/setup: lift dom0 creation out into create_dom0 function X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , Julien Grall , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Varad Gautam , paul@xen.org, Ian Jackson , Hongyan Xia , Amit Shah , =?utf-8?q?Ro?= =?utf-8?q?ger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" From: David Woodhouse It's about to become optional as __start_xen() grows a different path for live update, so move it out of the way. Signed-off-by: David Woodhouse --- 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 f789713b1b..ac93965be4 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -679,6 +679,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, char *kextra, + 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, + }; + 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; + } + dom0_cfg.max_vcpus = dom0_max_vcpus(); + + 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 = (char *)(image->string ? __va(image->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; + } + + /* + * 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) @@ -739,12 +825,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; uint64_t lu_mfnlist_phys = 0, lu_nr_pages = 0; struct lu_stream lu_stream; @@ -1889,94 +1969,29 @@ 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 "Multiple initrd candidates, picking module #%u\n", 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 > 0) && (initrdidx < mbi->mods_count) + ? mod + initrdidx : NULL, kextra, loader); + if ( dom0 == NULL ) 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();