From nobody Tue Feb 10 04:55:19 2026 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1580517223238652.1706637012699; Fri, 31 Jan 2020 16:33:43 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ixgig-00066L-Qk; Sat, 01 Feb 2020 00:33:06 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ixgig-000665-31 for xen-devel@lists.xenproject.org; Sat, 01 Feb 2020 00:33:06 +0000 Received: from bombadil.infradead.org (unknown [2607:7c80:54:e::133]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 692917f0-448a-11ea-b211-bc764e2007e4; Sat, 01 Feb 2020 00:33:05 +0000 (UTC) Received: from i7.infradead.org ([2001:8b0:10b:1:21e:67ff:fecb:7a92]) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1ixgie-0007N4-Ht; Sat, 01 Feb 2020 00:33:04 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.92 #3 (Red Hat Linux)) id 1ixgid-009ulQ-Aa; Sat, 01 Feb 2020 00:33:03 +0000 X-Inumbo-ID: 692917f0-448a-11ea-b211-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.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=9RgL2Z0Xollm7VQ7ZAaxx2QpOXyoyuKPohgfc0eH1Ss=; b=eFU58qvhYpUtIqy87KfpVaTJ92 5HEBBsN5oI+cAmfW4Ti/JZ5ybBrqQ6NltS7LQEWQ3nkp6ZNqrC6vwLcdsTVpxHA2SZdNrNVambHsT ZoHkBGYcKdl+gvUNTmKugfQovzfNNHmGKIqn2Wfv1ZAKaQS9nkPTZhryzBXSHWZsRk8sueBMAewN7 lnXv8ButxqqztB5CQeDuaLJj+EEgY+BXdCyWOXQq8hPe2X2AQBQsAljS39IBIlgldn0CGL/y5HVEA bfYCV3GjEx46hBRaDUlQqpk7GBwRDPJK3MBFFNbh3ujTzLDljhCZ7w0KNoHxpCcwbwkwcu/xDNLDa AcD+TnjA==; From: David Woodhouse To: xen-devel@lists.xenproject.org Date: Sat, 1 Feb 2020 00:33:03 +0000 Message-Id: <20200201003303.2363081-8-dwmw2@infradead.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <8a95f787ca93b23ee8d8c0b55fcc63d22a75c5f3.camel@infradead.org> References: <8a95f787ca93b23ee8d8c0b55fcc63d22a75c5f3.camel@infradead.org> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Subject: [Xen-devel] [PATCH 8/8] 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 , Ian Jackson , Hongyan Xia , Paul Durrant , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: David Woodhouse 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. Signed-off-by: David Woodhouse --- xen/arch/x86/setup.c | 169 +++++++++++++++++++++++-------------------- 1 file changed, 92 insertions(+), 77 deletions(-) diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 10209e6bfb..9d86722ecd 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -678,6 +678,92 @@ static unsigned int __init copy_bios_e820(struct e820e= ntry *map, unsigned int li return n; } =20 +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 =3D { + .flags =3D IS_ENABLED(CONFIG_TBOOT) ? XEN_DOMCTL_CDF_s3_integrity = : 0, + .max_evtchn_port =3D -1, + .max_grant_frames =3D -1, + .max_maptrack_frames =3D -1, + }; + struct domain *d; + char *cmdline; + + if ( opt_dom0_pvh ) + { + dom0_cfg.flags |=3D (XEN_DOMCTL_CDF_hvm | + ((hvm_hap_supported() && !opt_dom0_shadow) ? + XEN_DOMCTL_CDF_hap : 0)); + + dom0_cfg.arch.emulation_flags |=3D + XEN_X86_EMU_LAPIC | XEN_X86_EMU_IOAPIC | XEN_X86_EMU_VPCI; + } + dom0_cfg.max_vcpus =3D dom0_max_vcpus(); + + if ( iommu_enabled ) + dom0_cfg.flags |=3D XEN_DOMCTL_CDF_iommu; + + /* Create initial domain 0. */ + d =3D domain_create(get_initial_domain_id(), &dom0_cfg, !pv_shim); + if ( IS_ERR(d) || (alloc_dom0_vcpu0(d) =3D=3D NULL) ) + panic("Error creating domain 0\n"); + + /* Grab the DOM0 command line. */ + cmdline =3D (char *)(image->string ? __va(image->string) : NULL); + if ( (cmdline !=3D NULL) || (kextra !=3D NULL) ) + { + static char __initdata dom0_cmdline[MAX_GUEST_CMDLINE]; + + cmdline =3D cmdline_cook(cmdline, loader); + safe_strcpy(dom0_cmdline, cmdline); + + if ( kextra !=3D 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) =3D=3D 0) && acpi_disabled ) + { + printk("ACPI is disabled, notifying Domain 0 (acpi=3Doff)\n"); + safe_strcpy(acpi_param, "off"); + } + if ( (strlen(acpi_param) !=3D 0) && !strstr(dom0_cmdline, "acpi=3D= ") ) + { + safe_strcat(dom0_cmdline, " acpi=3D"); + safe_strcat(dom0_cmdline, acpi_param); + } + + cmdline =3D dom0_cmdline; + } + + /* + * Temporarily clear SMAP in CR4 to allow user-accesses in construct_d= om0(). + * This saves a large number of corner cases interactions with + * copy_from_user(). + */ + if ( cpu_has_smap ) + { + cr4_pv32_mask &=3D ~X86_CR4_SMAP; + write_cr4(read_cr4() & ~X86_CR4_SMAP); + } + + if ( construct_dom0(d, image, headroom, initrd, cmdline) !=3D 0 ) + panic("Could not construct domain 0\n"); + + if ( cpu_has_smap ) + { + write_cr4(read_cr4() | X86_CR4_SMAP); + cr4_pv32_mask |=3D X86_CR4_SMAP; + } + + return d; +} + /* How much of the directmap is prebuilt at compile time. */ #define PREBUILT_MAP_LIMIT (1 << L2_PAGETABLE_SHIFT) =20 @@ -697,12 +783,6 @@ void __init noreturn __start_xen(unsigned long mbi_p) .parity =3D 'n', .stop_bits =3D 1 }; - struct xen_domctl_createdomain dom0_cfg =3D { - .flags =3D IS_ENABLED(CONFIG_TBOOT) ? XEN_DOMCTL_CDF_s3_integrity = : 0, - .max_evtchn_port =3D -1, - .max_grant_frames =3D -1, - .max_maptrack_frames =3D -1, - }; const char *hypervisor_name; =20 /* Critical region without IDT or TSS. Any fault is deadly! */ @@ -1740,58 +1820,13 @@ void __init noreturn __start_xen(unsigned long mbi_= p) init_guest_cpuid(); init_guest_msr_policy(); =20 - if ( opt_dom0_pvh ) - { - dom0_cfg.flags |=3D (XEN_DOMCTL_CDF_hvm | - ((hvm_hap_supported() && !opt_dom0_shadow) ? - XEN_DOMCTL_CDF_hap : 0)); - - dom0_cfg.arch.emulation_flags |=3D - XEN_X86_EMU_LAPIC | XEN_X86_EMU_IOAPIC | XEN_X86_EMU_VPCI; - } - dom0_cfg.max_vcpus =3D dom0_max_vcpus(); - - if ( iommu_enabled ) - dom0_cfg.flags |=3D XEN_DOMCTL_CDF_iommu; - - /* Create initial domain 0. */ - dom0 =3D domain_create(get_initial_domain_id(), &dom0_cfg, !pv_shim); - if ( IS_ERR(dom0) || (alloc_dom0_vcpu0(dom0) =3D=3D NULL) ) - panic("Error creating domain 0\n"); - - /* Grab the DOM0 command line. */ - cmdline =3D (char *)(mod[0].string ? __va(mod[0].string) : NULL); - if ( (cmdline !=3D NULL) || (kextra !=3D NULL) ) - { - static char __initdata dom0_cmdline[MAX_GUEST_CMDLINE]; - - cmdline =3D cmdline_cook(cmdline, loader); - safe_strcpy(dom0_cmdline, cmdline); - - if ( kextra !=3D 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) =3D=3D 0) && acpi_disabled ) - { - printk("ACPI is disabled, notifying Domain 0 (acpi=3Doff)\n"); - safe_strcpy(acpi_param, "off"); - } - if ( (strlen(acpi_param) !=3D 0) && !strstr(dom0_cmdline, "acpi=3D= ") ) - { - safe_strcat(dom0_cmdline, " acpi=3D"); - safe_strcat(dom0_cmdline, acpi_param); - } - - cmdline =3D dom0_cmdline; - } - if ( xen_cpuidle ) xen_processor_pmbits |=3D XEN_PROCESSOR_PM_CX; =20 + printk("%sNX (Execute Disable) protection %sactive\n", + cpu_has_nx ? XENLOG_INFO : XENLOG_WARNING "Warning: ", + cpu_has_nx ? "" : "not "); + initrdidx =3D find_first_bit(module_map, mbi->mods_count); if ( initrdidx < mbi->mods_count ) initrd =3D mod + initrdidx; @@ -1801,34 +1836,14 @@ void __init noreturn __start_xen(unsigned long mbi_= p) "Multiple initrd candidates, picking module #%u\n", initrdidx); =20 - /* - * Temporarily clear SMAP in CR4 to allow user-accesses in construct_d= om0(). - * This saves a large number of corner cases interactions with - * copy_from_user(). - */ - if ( cpu_has_smap ) - { - cr4_pv32_mask &=3D ~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 sa= fely * above our heap. The second module, if present, is an initrd ramdisk. */ - if ( construct_dom0(dom0, mod, modules_headroom, initrd, cmdline) !=3D= 0 ) + dom0 =3D create_dom0(mod, modules_headroom, initrd, kextra, loader); + if ( dom0 =3D=3D NULL ) panic("Could not set up DOM0 guest OS\n"); =20 - if ( cpu_has_smap ) - { - write_cr4(read_cr4() | X86_CR4_SMAP); - cr4_pv32_mask |=3D X86_CR4_SMAP; - } - heap_init_late(); =20 init_trace_bufs(); --=20 2.21.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel